﻿Option Explicit On
Imports Microsoft.VisualBasic
Imports System
Imports System.Xml
Imports System.Data
Imports System.IO
Imports Microsoft.SqlServer.Server
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Globalization

Public Class ClassFunction

    Public Function InsertBooking(ByVal EventEdit As String, ByVal Booking_no As String, ByVal Booking_Code As String, ByVal Booking_name As String, ByVal Vehicle_no As String, ByVal Vehicle_Text As String, ByVal Vehicle_LOA As String, ByVal Vehicle_DWT As String, ByVal Vehicle_Draft As String, ByVal Vehicle_GRT As String, ByVal Date_From As String, ByVal Date_To As String, ByVal PORT As String, ByVal Vehicle_destination As String, ByVal Vehicle_TypeBuy As String, ByVal Remark As String, ByVal Status As String, ByVal Remark_VPS As String, ByVal VPS_approve As String, ByVal Remark_MRI As String, ByVal MRI_approve As String, ByVal Marketing_approve As String, ByVal Product_Name As String, ByVal Product_Amount As String, ByVal MAgent_no As String, ByVal MAgent_name As String, ByVal SAgent_no As String, ByVal SAgent_name As String, ByVal Booking_Date As String, ByVal Booking_Time As String, ByVal Buyer As String, ByVal Seller As String, ByVal Product_Unit As String, ByVal File_Upload As String, ByVal Vehicle_CNTRY As String, ByVal Lay_Time As String, ByVal MKT_Product As String, ByVal MKT_Custom As String, ByVal MKT_Finance As String, ByVal BunkerFO_chk As String, ByVal BunkerDo_Chk As String, ByVal BunkerFO_Point As String, ByVal BunkerDO_Point As String, ByVal BunkerDetail As String, ByVal Water_Point As String, ByVal Payin As String, ByVal StandardTime As String, ByVal Credit_Limit As String, ByVal Demurrage As String, ByVal Demurrage_Money As String, ByVal Electricity As String, ByVal Shifting As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (EventEdit = "") Then
            sql = "INSERT Booking(Booking_no,Booking_Code,Booking_name,Vehicle_no,Vehicle_Text,Vehicle_LOA,Vehicle_DWT,Vehicle_Draft,Vehicle_GRT,Date_From,Date_To,PORT,Vehicle_destination,Vehicle_TypeBuy,Remark,Status,Remark_VPS,VPS_approve,Remark_MRI,MRI_approve,Marketing_approve,Product_Name,Product_Amount,MAgent_no,MAgent_name,Vehicle_CNTRY,Lay_Time,MKT_Product,MKT_Custom,MKT_Finance,SAgent_no,SAgent_name,Booking_Date,Booking_Time,Buyer,Seller,File_Upload,Product_Unit,BunkerFO_chk,BunkerDO_chk,BunkerFO_Point,BunkerDO_Point,BunkerDetail,Water_Point,Payin,StandardTime,Credit_Limit,Status_Pay,Demurrage,Demurrage_Money,Electricity,Shifting) "
            sql &= " VALUES(@Booking_no,@Customer_no,@Customer_name,@Vehicle_no,@Vehicle_Text,@Vehicle_LOA,@Vehicle_DWT,@Vehicle_Draft,@Vehicle_GRT,@Date_From,@Date_To,@PORT,@Vehicle_destination,@Vehicle_TypeBuy,@Remark,@Status,@Remark_VPS,@VPS_approve,@Remark_MRI,@MRI_approve,@Marketing_approve,@Product_Name,@Product_Amount,@MAgent_no,@MAgent_name,@Vehicle_CNTRY,@Lay_Time,@MKT_Product,@MKT_Custom,@MKT_Finance,@SAgent_no,@SAgent_name,@Booking_Date,@Booking_Time,@Buyer,@Seller,@File_Upload,@Product_Unit,@BunkerFO_chk,@BunkerDO_chk,@BunkerFO_Point,@BunkerDO_Point,@BunkerDetail,@Water_Point,@Payin,@StandardTime,@Credit_Limit,'N',@Demurrage,@Demurrage_Money,@Electricity,@Shifting)"
        Else
            sql = " UPDATE Booking SET "
            sql &= " Vehicle_no = @Vehicle_no,Date_From = @Date_From,Date_To=@Date_To"
            sql &= ",PORT = @PORT,Vehicle_destination=@Vehicle_destination,Vehicle_TypeBuy=@Vehicle_TypeBuy,Remark=@Remark "
            sql &= ",Vehicle_Text=@Vehicle_Text,Vehicle_LOA=@Vehicle_LOA,Vehicle_DWT=@Vehicle_DWT,Vehicle_Draft=@Vehicle_Draft,Vehicle_GRT=@Vehicle_GRT "
            sql &= " ,Product_name=@Product_name,Product_Amount=@Product_Amount"
            sql &= " ,MAgent_no = @MAgent_no,MAgent_name = @MAgent_name , Vehicle_CNTRY=@Vehicle_CNTRY,Lay_Time=@Lay_Time "
            sql &= " ,SAgent_no = @SAgent_no ,SAgent_name = @SAgent_name, Booking_Date = @Booking_Date,Booking_Time = @Booking_Time,Buyer=@Buyer,Seller=@Seller,File_Upload=@File_Upload,Product_Unit=@Product_Unit "
            sql &= " ,BunkerFO_chk = @BunkerFO_chk,BunkerDO_chk = @BunkerDO_chk,BunkerFO_Point = @BunkerFO_Point,BunkerDO_Point=@BunkerDO_Point,BunkerDetail=@BunkerDetail,Water_Point=@Water_Point "
            sql &= " ,StandardTime=@StandardTime,Demurrage=@Demurrage,Demurrage_Money=@Demurrage_Money "
            sql &= " ,Electricity = @Electricity"
            sql &= " Where Booking_no = @Booking_no"
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 50).Value = Booking_Code
        cmd.Parameters.Add("@Customer_name", SqlDbType.NVarChar, 200).Value = Booking_name
        cmd.Parameters.Add("@Vehicle_no", SqlDbType.NVarChar, 10).Value = Vehicle_no
        cmd.Parameters.Add("@Vehicle_Text", SqlDbType.NVarChar, 200).Value = Vehicle_Text
        cmd.Parameters.Add("@Vehicle_LOA", SqlDbType.NVarChar, 10).Value = Vehicle_LOA
        cmd.Parameters.Add("@Vehicle_DWT", SqlDbType.NVarChar, 10).Value = Vehicle_DWT
        cmd.Parameters.Add("@Vehicle_Draft", SqlDbType.NVarChar, 10).Value = Vehicle_Draft
        cmd.Parameters.Add("@Vehicle_GRT", SqlDbType.NVarChar, 10).Value = Vehicle_GRT
        cmd.Parameters.Add("@Date_From", SqlDbType.NVarChar, 12).Value = Date_From
        cmd.Parameters.Add("@Date_To", SqlDbType.NVarChar, 12).Value = Date_To
        cmd.Parameters.Add("@PORT", SqlDbType.NVarChar, 1).Value = PORT
        cmd.Parameters.Add("@Vehicle_destination", SqlDbType.NVarChar, 1).Value = Vehicle_destination
        cmd.Parameters.Add("@Vehicle_TypeBuy", SqlDbType.NVarChar, 1).Value = Vehicle_TypeBuy
        cmd.Parameters.Add("@Remark", SqlDbType.Text).Value = Remark
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status
        cmd.Parameters.Add("@Remark_VPS", SqlDbType.Text).Value = Remark_VPS
        cmd.Parameters.Add("@VPS_approve", SqlDbType.NVarChar, 50).Value = VPS_approve
        cmd.Parameters.Add("@Remark_MRI", SqlDbType.Text).Value = Remark_MRI
        cmd.Parameters.Add("@MRI_approve", SqlDbType.NVarChar, 50).Value = MRI_approve
        cmd.Parameters.Add("@Marketing_approve", SqlDbType.NVarChar, 50).Value = Marketing_approve
        cmd.Parameters.Add("@Product_Name", SqlDbType.NVarChar, 200).Value = Product_Name
        cmd.Parameters.Add("@Product_Amount", SqlDbType.NVarChar, 10).Value = Product_Amount
        cmd.Parameters.Add("@MAgent_no", SqlDbType.NVarChar, 10).Value = MAgent_no
        cmd.Parameters.Add("@MAgent_name", SqlDbType.NVarChar, 200).Value = MAgent_name
        cmd.Parameters.Add("@Vehicle_CNTRY", SqlDbType.NVarChar, 2).Value = Vehicle_CNTRY
        cmd.Parameters.Add("@Lay_Time", SqlDbType.NVarChar, 20).Value = Lay_Time
        cmd.Parameters.Add("@MKT_Product", SqlDbType.NVarChar, 1).Value = MKT_Product
        cmd.Parameters.Add("@MKT_Custom", SqlDbType.NVarChar, 1).Value = MKT_Custom
        cmd.Parameters.Add("@MKT_Finance", SqlDbType.NVarChar, 1).Value = MKT_Finance
        cmd.Parameters.Add("@SAgent_no", SqlDbType.NVarChar, 10).Value = SAgent_no
        cmd.Parameters.Add("@SAgent_name", SqlDbType.NVarChar, 200).Value = SAgent_name
        cmd.Parameters.Add("@Booking_Date", SqlDbType.NVarChar, 12).Value = Booking_Date
        cmd.Parameters.Add("@Booking_Time", SqlDbType.NVarChar, 5).Value = Booking_Time
        cmd.Parameters.Add("@Buyer", SqlDbType.NVarChar, 250).Value = Buyer
        cmd.Parameters.Add("@Seller", SqlDbType.NVarChar, 250).Value = Seller
        cmd.Parameters.Add("@File_Upload", SqlDbType.NVarChar, 100).Value = File_Upload
        cmd.Parameters.Add("@Product_Unit", SqlDbType.NVarChar, 50).Value = Product_Unit
        cmd.Parameters.Add("@BunkerFO_chk", SqlDbType.NVarChar, 1).Value = BunkerFO_chk
        cmd.Parameters.Add("@BunkerDO_chk", SqlDbType.NVarChar, 1).Value = BunkerDo_Chk
        cmd.Parameters.Add("@BunkerFO_Point", SqlDbType.NVarChar, 10).Value = BunkerFO_Point
        cmd.Parameters.Add("@BunkerDO_Point", SqlDbType.NVarChar, 10).Value = BunkerDO_Point
        cmd.Parameters.Add("@BunkerDetail", SqlDbType.NVarChar, 500).Value = BunkerDetail
        cmd.Parameters.Add("@Water_Point", SqlDbType.NVarChar, 10).Value = Water_Point
        cmd.Parameters.Add("@Payin", SqlDbType.NVarChar, 1).Value = Payin
        cmd.Parameters.Add("@StandardTime", SqlDbType.NVarChar, 10).Value = StandardTime
        cmd.Parameters.Add("@Credit_Limit", SqlDbType.NVarChar, 1).Value = Credit_Limit
        cmd.Parameters.Add("@Demurrage", SqlDbType.NVarChar, 50).Value = Demurrage
        cmd.Parameters.Add("@Demurrage_Money", SqlDbType.NVarChar, 1).Value = Demurrage_Money
        cmd.Parameters.Add("@Electricity", SqlDbType.NVarChar, 10).Value = Electricity
        cmd.Parameters.Add("@Shifting", SqlDbType.NVarChar, 1).Value = Shifting
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDateMarketing_Approve(ByVal Booking_no As String, ByVal Marketing_approve As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking_Log SET "
        sql &= " Marketing_approve = @Marketing_approve  "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Marketing_approve", SqlDbType.NVarChar, 50).Value = Marketing_approve

        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBooking_Reject(ByVal Booking_no As String, ByVal ChkReject As String, ByVal RejectRemark As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= "ChkReject = @ChkReject, "
        sql &= "RejectRemark = @RejectRemark "
        sql &= "WHERE Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no.ToString()
        cmd.Parameters.Add("@ChkReject", SqlDbType.NVarChar, 1).Value = ChkReject
        cmd.Parameters.Add("@RejectRemark", SqlDbType.NVarChar, 200).Value = RejectRemark.ToString()

        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertPre_Booking(ByVal EventEdit As String, ByVal Booking_no As String, ByVal Booking_Code As String, ByVal Booking_name As String, ByVal Vehicle_no As String, ByVal Vehicle_Text As String, ByVal Vehicle_LOA As String, ByVal Vehicle_DWT As String, ByVal Vehicle_Draft As String, ByVal Vehicle_GRT As String, ByVal Date_From As String, ByVal Date_To As String, ByVal PORT As String, ByVal Vehicle_destination As String, ByVal Vehicle_TypeBuy As String, ByVal Remark As String, ByVal Status As String, ByVal MAgent_no As String, ByVal MAgent_name As String, ByVal Vehicle_CNTRY As String, ByVal Water_Point As String, ByVal Electricity As String, ByVal BunkerFO_chk As String, ByVal BunkerDO_chk As String, ByVal BunkerFO_Point As String, ByVal BunkerDO_Point As String, ByVal BunkerDetail As String, ByVal SAgent_no As String, ByVal SAgent_name As String, ByVal Booking_Date As String, ByVal Booking_Time As String, ByVal Lay_Time As String, ByVal Demurrage As String, ByVal Demurrage_Money As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (EventEdit = "") Then
            sql = "INSERT Pre_Booking(Booking_no,Booking_Code,Booking_name,Vehicle_no,Vehicle_Text,Vehicle_LOA,Vehicle_DWT,Vehicle_Draft,Vehicle_GRT,Date_From,Date_To,PORT,Vehicle_destination,Vehicle_TypeBuy,Remark,Status,MAgent_no,MAgent_name,Vehicle_CNTRY,Water_Point,Electricity,BunkerFO_chk,BunkerDO_chk,BunkerFO_Point,BunkerDO_Point,BunkerDetail,SAgent_no,SAgent_name,Booking_Date,Booking_Time,Lay_Time,Demurrage,Demurrage_Money) "
            sql &= " VALUES(@Booking_no,@Customer_no,@Customer_name,@Vehicle_no,@Vehicle_Text,@Vehicle_LOA,@Vehicle_DWT,@Vehicle_Draft,@Vehicle_GRT,@Date_From,@Date_To,@PORT,@Vehicle_destination,@Vehicle_TypeBuy,@Remark,@Status,@MAgent_no,@MAgent_name,@Vehicle_CNTRY,@Water_Point,@Electricity,@BunkerFO_chk,@BunkerDO_chk,@BunkerFO_Point,@BunkerDO_Point,@BunkerDetail,@SAgent_no,@SAgent_name,@Booking_Date,@Booking_Time,@Lay_Time,@Demurrage,@Demurrage_Money)"
        Else
            sql = " UPDATE Pre_Booking SET "
            sql &= " Booking_Code = @Customer_no,Booking_name=@Customer_name,Vehicle_no = @Vehicle_no,Date_From = @Date_From,Date_To=@Date_To"
            sql &= ",PORT = @PORT,Vehicle_destination=@Vehicle_destination,Vehicle_TypeBuy=@Vehicle_TypeBuy,Remark=@Remark,Status=@Status "
            sql &= ",Vehicle_Text=@Vehicle_Text,Vehicle_LOA=@Vehicle_LOA,Vehicle_DWT=@Vehicle_DWT,Vehicle_Draft=@Vehicle_Draft,Vehicle_GRT=@Vehicle_GRT "
            sql &= " ,MAgent_no = @MAgent_no,MAgent_name = @MAgent_name , Vehicle_CNTRY=@Vehicle_CNTRY "
            sql &= " ,Water_Point=@Water_Point,Electricity = @Electricity "
            sql &= " ,BunkerFO_chk = @BunkerFO_chk,BunkerDO_chk = @BunkerDO_chk,BunkerFO_Point = @BunkerFO_Point,BunkerDO_Point = @BunkerDO_Point,BunkerDetail = @BunkerDetail"
            sql &= " ,SAgent_no = @SAgent_no,SAgent_name = @SAgent_name,Booking_Date = @Booking_Date,Booking_Time = @Booking_Time"
            sql &= " ,Lay_Time = @Lay_Time , Demurrage = @Demurrage ,Demurrage_Money = @Demurrage_Money "
            sql &= " Where Booking_no = @Booking_no"
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 50).Value = Booking_Code
        cmd.Parameters.Add("@Customer_name", SqlDbType.NVarChar, 200).Value = Booking_name
        cmd.Parameters.Add("@Vehicle_no", SqlDbType.NVarChar, 10).Value = Vehicle_no
        cmd.Parameters.Add("@Vehicle_Text", SqlDbType.NVarChar, 200).Value = Vehicle_Text
        cmd.Parameters.Add("@Vehicle_LOA", SqlDbType.NVarChar, 10).Value = Vehicle_LOA
        cmd.Parameters.Add("@Vehicle_DWT", SqlDbType.NVarChar, 10).Value = Vehicle_DWT
        cmd.Parameters.Add("@Vehicle_Draft", SqlDbType.NVarChar, 10).Value = Vehicle_Draft
        cmd.Parameters.Add("@Vehicle_GRT", SqlDbType.NVarChar, 10).Value = Vehicle_GRT
        cmd.Parameters.Add("@Date_From", SqlDbType.NVarChar, 12).Value = Date_From
        cmd.Parameters.Add("@Date_To", SqlDbType.NVarChar, 12).Value = Date_To
        cmd.Parameters.Add("@PORT", SqlDbType.NVarChar, 1).Value = PORT
        cmd.Parameters.Add("@Vehicle_destination", SqlDbType.NVarChar, 1).Value = Vehicle_destination
        cmd.Parameters.Add("@Vehicle_TypeBuy", SqlDbType.NVarChar, 1).Value = Vehicle_TypeBuy
        cmd.Parameters.Add("@Remark", SqlDbType.Text).Value = Remark
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status
        cmd.Parameters.Add("@MAgent_no", SqlDbType.NVarChar, 10).Value = MAgent_no
        cmd.Parameters.Add("@MAgent_name", SqlDbType.NVarChar, 200).Value = MAgent_name
        cmd.Parameters.Add("@Vehicle_CNTRY", SqlDbType.NVarChar, 2).Value = Vehicle_CNTRY
        cmd.Parameters.Add("@Water_Point", SqlDbType.NVarChar, 10).Value = Water_Point
        cmd.Parameters.Add("@Electricity", SqlDbType.NVarChar, 10).Value = Electricity
        cmd.Parameters.Add("@BunkerFO_chk", SqlDbType.NVarChar, 1).Value = BunkerFO_chk
        cmd.Parameters.Add("@BunkerDO_chk", SqlDbType.NVarChar, 1).Value = BunkerDO_chk
        cmd.Parameters.Add("@BunkerFO_Point", SqlDbType.NVarChar, 1).Value = BunkerFO_Point
        cmd.Parameters.Add("@BunkerDO_Point", SqlDbType.NVarChar, 1).Value = BunkerDO_Point
        cmd.Parameters.Add("@BunkerDetail", SqlDbType.NVarChar, 1).Value = BunkerDetail
        cmd.Parameters.Add("@SAgent_no", SqlDbType.NVarChar, 10).Value = SAgent_no
        cmd.Parameters.Add("@SAgent_name", SqlDbType.NVarChar, 200).Value = SAgent_name
        cmd.Parameters.Add("@Booking_Date", SqlDbType.NVarChar, 12).Value = Booking_Date
        cmd.Parameters.Add("@Booking_Time", SqlDbType.NVarChar, 5).Value = Booking_Time
        cmd.Parameters.Add("@Lay_Time", SqlDbType.NVarChar, 20).Value = Lay_Time
        cmd.Parameters.Add("@Demurrage", SqlDbType.NVarChar, 50).Value = Demurrage
        cmd.Parameters.Add("@Demurrage_Money", SqlDbType.NVarChar, 1).Value = Demurrage_Money

        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdatePREBookingStatusOneField(ByVal Booking_no As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Pre_Booking SET "
        sql &= " Status = @Status "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status

        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBookingStatusOneField(ByVal Booking_no As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Status = @Status "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status

        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBookingProduct_Status(ByVal Booking_no As String, ByVal Owner As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking_Product SET "
        sql &= " Status = @Status "
        sql &= " Where Booking_no = @Booking_no"
        sql &= " AND Owner_Product_no = @Owner_Product_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status
        cmd.Parameters.Add("@Owner_Product_no", SqlDbType.NVarChar, 10).Value = Owner
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateCancelBooking(ByVal Booking_no As String, ByVal Status As String, ByVal Cancel_By As String, ByVal Cancel_Description As String, ByVal Vps_Acknowledge As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Status = @Status "
        If (Vps_Acknowledge <> "") Then
            sql &= " ,Vps_Acknowledge = @Vps_Acknowledge "
        Else
            sql &= " , Cancel_By = @Cancel_By ,Cancel_Description = @Cancel_Description "
        End If
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status
        If (Vps_Acknowledge <> "") Then
            cmd.Parameters.Add("@Vps_Acknowledge", SqlDbType.NVarChar, 50).Value = Vps_Acknowledge
        Else
            cmd.Parameters.Add("@Cancel_By", SqlDbType.NVarChar, 50).Value = Cancel_By
            cmd.Parameters.Add("@Cancel_Description", SqlDbType.NVarChar, 500).Value = Cancel_Description
        End If

        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateStatus_Pay(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Status_Pay = 'Y' "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertPayment_Bank(ByVal Tracking As String, ByVal Booking_no As String, ByVal Customer As String, ByVal PaymentAmt As String, ByVal BankAccount As String, ByVal Date_Time As String, ByVal Status As String, ByVal Detail As String, ByVal Bank As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " Insert Payment_Bank(Tracking,Booking_no,Customer,PaymentAmt,BankAccount,Date_Time,Status,Detail,Bank) "
        sql &= " VALUES (@Tracking,@Booking_no,@Customer,@PaymentAmt,@BankAccount,@Date_Time,@Status,@Detail,@Bank) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Tracking", SqlDbType.NVarChar, 20).Value = Tracking
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Customer", SqlDbType.NVarChar, 20).Value = Customer
        cmd.Parameters.Add("@PaymentAmt", SqlDbType.NVarChar, 20).Value = PaymentAmt
        cmd.Parameters.Add("@BankAccount", SqlDbType.NVarChar, 20).Value = BankAccount
        cmd.Parameters.Add("@Date_Time", SqlDbType.NVarChar, 20).Value = Date_Time
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 5).Value = Status
        cmd.Parameters.Add("@Detail", SqlDbType.NVarChar, 500).Value = Detail
        cmd.Parameters.Add("@Bank", SqlDbType.NVarChar, 20).Value = Bank
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdatePayment_Bank(ByVal Tracking As String, ByVal Status As String, ByVal Detail As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " Update Payment_Bank SET "
        sql &= " Status = @Status "
        sql &= " ,Detail = @Detail "
        sql &= " WHERE Tracking = @Tracking"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Tracking", SqlDbType.NVarChar, 20).Value = Tracking
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 5).Value = Status
        cmd.Parameters.Add("@Detail", SqlDbType.NVarChar, 500).Value = Detail
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBooking_Product_Index(ByVal Booking_no As String, ByVal Product_no As String, ByVal Product_Index As String, ByVal Product_Shore As String, ByVal Product_Line As String, ByVal Product_Facility As String, ByVal Product_Buyer_name As String, ByVal Product_Seller_name As String, ByVal BP_Code As String, ByVal LoadDestination As String, ByVal DischDestination As String, ByVal Product_Amount As String, ByVal Owner As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking_Product SET "
        sql &= " Product_Index = @Product_Index,Product_Shore = @Product_Shore,Product_Line = @Product_Line,Product_Facility = @Product_Facility,BP_Code = @BP_Code "
        sql &= " Where Booking_no = @Booking_no And Product_no = @Product_no "
        If (Product_Buyer_name <> "") Then
            sql &= " and Product_Buyer_name = @Product_Buyer_name"
        End If
        If (Product_Seller_name <> "") Then
            sql &= " and Product_Seller_name = @Product_Seller_name"
        End If
        If (BP_Code <> "") Then
            sql &= " and BP_Code Not in (" & BP_Code & ") "
        End If
        If (LoadDestination <> "") Then
            sql &= " and LoadDestination = @LoadDestination " & vbCrLf
        End If
        If (DischDestination <> "") Then
            sql &= " and DischDestination = @DischDestination " & vbCrLf
        End If
        If (Product_Amount <> "") Then
            sql &= " and Product_Amount = @Product_Amount " & vbCrLf
        End If
        If (Owner <> "") Then
            sql &= " and Owner_Product_no = @Owner_Product_no " & vbCrLf
        End If
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Product_Index", SqlDbType.NVarChar, 2).Value = Product_Index
        cmd.Parameters.Add("@Product_Shore", SqlDbType.NVarChar, 10).Value = Product_Shore
        cmd.Parameters.Add("@Product_Line", SqlDbType.NVarChar, 10).Value = Product_Line
        cmd.Parameters.Add("@Product_Facility", SqlDbType.NVarChar, 10).Value = Product_Facility
        cmd.Parameters.Add("@Product_Buyer_name", SqlDbType.NVarChar, 500).Value = Product_Buyer_name
        cmd.Parameters.Add("@Product_Seller_name", SqlDbType.NVarChar, 500).Value = Product_Seller_name
        cmd.Parameters.Add("@BP_Code", SqlDbType.NVarChar, 25).Value = Booking_no & Product_no & Product_Index

        cmd.Parameters.Add("@LoadDestination", SqlDbType.NVarChar, 200).Value = LoadDestination
        cmd.Parameters.Add("@DischDestination", SqlDbType.NVarChar, 200).Value = DischDestination
        cmd.Parameters.Add("@Product_Amount", SqlDbType.NVarChar, 10).Value = Product_Amount
        cmd.Parameters.Add("@Owner_Product_no", SqlDbType.NVarChar, 10).Value = Owner
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateClear_Index(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking_Product SET "
        sql &= " BP_Code = 'xxxx' "
        sql &= " Where Booking_no = @Booking_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateCancelVps_Acknowledge(ByVal Booking_no As String, ByVal Vps_Acknowledge As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Vps_Acknowledge = @Vps_Acknowledge "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Vps_Acknowledge", SqlDbType.NVarChar, 50).Value = Vps_Acknowledge
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateCancelMKT_Acknowledge(ByVal Booking_no As String, ByVal MKT_Acknowledge As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " MKT_Acknowledge = @MKT_Acknowledge "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@MKT_Acknowledge", SqlDbType.NVarChar, 50).Value = MKT_Acknowledge
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateCreditLimit(ByVal Booking_no As String, ByVal Credit_Limit As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Credit_Limit = @Credit_Limit  "

        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Credit_Limit", SqlDbType.NVarChar, 1).Value = Credit_Limit
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBookingCreditLimit(ByVal Booking_no As String, ByVal Iport_Number As String, ByVal Sale_Order As String, ByVal Release_By As String, ByVal Ralease_Time As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Booking_Credit_limit(Booking_no,Iport_Number,Sale_Order,Release_By,Ralease_Time) "
        sql &= " VALUES(@Booking_no,@Iport_Number,@Sale_Order,@Release_By,@Ralease_Time) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Iport_Number", SqlDbType.NVarChar, 12).Value = Iport_Number
        cmd.Parameters.Add("@Sale_Order", SqlDbType.NVarChar, 20).Value = Sale_Order
        cmd.Parameters.Add("@Release_By", SqlDbType.NVarChar, 50).Value = Release_By
        cmd.Parameters.Add("@Ralease_Time", SqlDbType.NVarChar, 20).Value = Ralease_Time
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function Insert_CountVessel_Liquid(ByVal Booking_no As String, ByVal Number As String, ByVal Month As String, ByVal Year As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT CountVessel_Liquid(Booking_no,Number,Month,Year) "
        sql &= " VALUES(@Booking_no,@Number,@Month,@Year) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Number", SqlDbType.NVarChar, 4).Value = Number
        cmd.Parameters.Add("@Month", SqlDbType.NVarChar, 2).Value = Month
        cmd.Parameters.Add("@Year", SqlDbType.NVarChar, 4).Value = Year
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBooking_Bill_to(ByVal Booking_no As String, ByVal Bill_To_no As String, ByVal Bill_To_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Bill_To_no = @Bill_To_no , Bill_To_name = @Bill_To_name"
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Bill_To_no", SqlDbType.NVarChar, 10).Value = Bill_To_no
        cmd.Parameters.Add("@Bill_To_name", SqlDbType.NVarChar, 200).Value = Bill_To_name
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateVPSBooking(ByVal Booking_no As String, ByVal Remark_VPS As String, ByVal VPS_approve As String, ByVal Status As String, ByVal Remark_MRI As String, ByVal MRI_approve As String, ByVal Marketing_approve As String, ByVal Payin As String, ByVal Bill_To_no As String, ByVal Bill_To_name As String, ByVal Shifting As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Status = @Status , Remark_VPS = @Remark_VPS , VPS_approve = @VPS_approve , Remark_MRI = @Remark_MRI , MRI_approve = @MRI_approve "
        sql &= " ,Bill_To_no = @Bill_To_no , Bill_To_name = @Bill_To_name,Shifting = @Shifting "
        If (Marketing_approve <> "") Then
            sql &= " , Marketing_approve = @Marketing_approve "
        End If
        If (Payin <> "") Then
            sql &= " , Payin = @Payin"
        End If
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status
        cmd.Parameters.Add("@Remark_VPS", SqlDbType.Text).Value = Remark_VPS
        cmd.Parameters.Add("@VPS_approve", SqlDbType.NVarChar, 50).Value = VPS_approve
        cmd.Parameters.Add("@Remark_MRI", SqlDbType.Text).Value = Remark_MRI
        cmd.Parameters.Add("@MRI_approve", SqlDbType.NVarChar, 50).Value = MRI_approve
        If (Marketing_approve <> "") Then
            cmd.Parameters.Add("@Marketing_approve", SqlDbType.NVarChar, 50).Value = Marketing_approve
        End If
        If (Payin <> "") Then
            cmd.Parameters.Add("@Payin", SqlDbType.NVarChar, 1).Value = Payin
        End If
        cmd.Parameters.Add("@Bill_To_no", SqlDbType.NVarChar, 10).Value = Bill_To_no
        cmd.Parameters.Add("@Bill_To_name", SqlDbType.NVarChar, 200).Value = Bill_To_name
        cmd.Parameters.Add("@Shifting", SqlDbType.NVarChar, 1).Value = Shifting
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateSaleBooking(ByVal Booking_no As String, ByVal MKT_Product As String, ByVal MKT_Custom As String, ByVal MKT_Finance As String, ByVal MKT_Approve As String, ByVal Date_From As String, ByVal Date_To As String, ByVal Shifting As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " MKT_Product = @MKT_Product  , MKT_Custom = @MKT_Custom, MKT_Finance = @MKT_Finance , MKT_Approve = @MKT_Approve ,Date_From = @Date_From , Date_To = @Date_To ,Shifting = @Shifting "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@MKT_Product", SqlDbType.NVarChar, 1).Value = MKT_Product
        cmd.Parameters.Add("@MKT_Custom", SqlDbType.NVarChar, 1).Value = MKT_Custom
        cmd.Parameters.Add("@MKT_Finance", SqlDbType.NVarChar, 1).Value = MKT_Finance
        cmd.Parameters.Add("@MKT_Approve", SqlDbType.NVarChar, 50).Value = MKT_Approve
        cmd.Parameters.Add("@Date_From", SqlDbType.NVarChar, 12).Value = Date_From
        cmd.Parameters.Add("@Date_To", SqlDbType.NVarChar, 12).Value = Date_To
        cmd.Parameters.Add("@Shifting", SqlDbType.NVarChar, 1).Value = Shifting
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBookingVehicle(ByVal Booking_no As String, ByVal Vehicle_no As String, ByVal Vehicle_Text As String, ByVal Vehicle_LOA As String, ByVal Vehicle_DWT As String, ByVal Vehicle_Draft As String, ByVal Vehicle_GRT As String, ByVal Vehicle_CNTRY As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Vehicle_no = @Vehicle_no , Vehicle_Text = @Vehicle_Text , Vehicle_LOA = @Vehicle_LOA , Vehicle_DWT = @Vehicle_DWT , Vehicle_Draft = @Vehicle_Draft , Vehicle_GRT = @Vehicle_GRT , Vehicle_CNTRY = @Vehicle_CNTRY "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Vehicle_no", SqlDbType.NVarChar, 10).Value = Vehicle_no
        cmd.Parameters.Add("@Vehicle_Text", SqlDbType.NVarChar, 200).Value = Vehicle_Text
        cmd.Parameters.Add("@Vehicle_LOA", SqlDbType.NVarChar, 10).Value = Vehicle_LOA
        cmd.Parameters.Add("@Vehicle_DWT", SqlDbType.NVarChar, 10).Value = Vehicle_DWT
        cmd.Parameters.Add("@Vehicle_Draft", SqlDbType.NVarChar, 10).Value = Vehicle_Draft
        cmd.Parameters.Add("@Vehicle_GRT", SqlDbType.NVarChar, 10).Value = Vehicle_GRT
        cmd.Parameters.Add("@Vehicle_CNTRY", SqlDbType.NVarChar, 2).Value = Vehicle_CNTRY
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBookingAgentForActual(ByVal Booking_no As String, ByVal MAgent_no As String, ByVal MAgent_name As String, ByVal Bill_to As String, ByVal Bill_toname As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " MAgent_no = @MAgent_no , MAgent_name = @MAgent_name , Bill_To_no = @Bill_To_no , Bill_To_Name = @Bill_To_Name "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@MAgent_no", SqlDbType.NVarChar, 10).Value = MAgent_no
        cmd.Parameters.Add("@MAgent_name", SqlDbType.NVarChar, 200).Value = MAgent_name
        cmd.Parameters.Add("@Bill_To_no", SqlDbType.NVarChar, 10).Value = Bill_to
        cmd.Parameters.Add("@Bill_To_Name", SqlDbType.NVarChar, 200).Value = Bill_toname
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBookingAgent(ByVal Booking_no As String, ByVal MAgent_no As String, ByVal MAgent_name As String, ByVal SAgent_no As String, ByVal SAgent_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " MAgent_no = @MAgent_no , MAgent_name = @MAgent_name , SAgent_no = @SAgent_no , SAgent_name = @SAgent_name "
        sql &= " Where Booking_no = @Booking_no"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@MAgent_no", SqlDbType.NVarChar, 10).Value = MAgent_no
        cmd.Parameters.Add("@MAgent_name", SqlDbType.NVarChar, 200).Value = MAgent_name
        cmd.Parameters.Add("@SAgent_no", SqlDbType.NVarChar, 10).Value = SAgent_no
        cmd.Parameters.Add("@SAgent_name", SqlDbType.NVarChar, 200).Value = SAgent_name
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_Log(ByVal Booking_Log As String, ByVal Booking_no As String, ByVal Booking_Code As String, ByVal Booking_name As String, ByVal Vehicle_no As String, ByVal Vehicle_Text As String, ByVal Vehicle_LOA As String, ByVal Vehicle_DWT As String, ByVal Vehicle_Draft As String, ByVal Vehicle_GRT As String, ByVal Date_From As String, ByVal Date_To As String, ByVal PORT As String, ByVal Vehicle_destination As String, ByVal Vehicle_TypeBuy As String, ByVal Remark As String, ByVal Status As String, ByVal Remark_VPS As String, ByVal VPS_approve As String, ByVal Remark_MRI As String, ByVal MRI_approve As String, ByVal Marketing_approve As String, ByVal Product_Name As String, ByVal Product_Amount As String, ByVal MAgent_no As String, ByVal MAgent_name As String, ByVal SAgent_no As String, ByVal SAgent_name As String, ByVal Booking_Date As String, ByVal Booking_Time As String, ByVal Buyer As String, ByVal Seller As String, ByVal Product_Unit As String, ByVal File_Upload As String, ByVal Vehicle_CNTRY As String, ByVal Lay_Time As String, ByVal MKT_Product As String, ByVal MKT_Custom As String, ByVal MKT_Finance As String, ByVal BunkerFO_chk As String, ByVal BunkerDo_Chk As String, ByVal BunkerFO_Point As String, ByVal BunkerDO_Point As String, ByVal BunkerDetail As String, ByVal Water_Point As String, ByVal MKT_Approve As String, ByVal Cancel_By As String, ByVal Cancel_Description As String, ByVal Vps_Acknowledge As String, ByVal MKT_Acknowledge As String, ByVal Payin As String, ByVal Bill_To_no As String, ByVal Bill_To_name As String, ByVal StandardTime As String, ByVal Credit_Limit As String, ByVal Status_Pay As String, ByVal Demurrage As String, ByVal Demurrage_Money As String, ByVal Electricity As String, ByVal Shifting As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        'Owner Booking คือ username ผู้ที่ทำการ Booking ให้
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Booking_Log(Booking_Log,Booking_no,Booking_Code,Booking_name,Vehicle_no,Vehicle_Text,Vehicle_LOA,Vehicle_DWT,Vehicle_Draft,Vehicle_GRT,Date_From,Date_To,PORT,Vehicle_destination,Vehicle_TypeBuy,Remark,Status,Remark_VPS,VPS_approve,Remark_MRI,MRI_approve,Marketing_approve,Product_Name,Product_Amount,MAgent_no,MAgent_name,Vehicle_CNTRY,Lay_Time,MKT_Product,MKT_Custom,MKT_Finance,SAgent_no,SAgent_name,Booking_Date,Booking_Time,Buyer,Seller,File_Upload,Product_Unit,BunkerFO_chk,BunkerDO_chk,BunkerFO_Point,BunkerDO_Point,BunkerDetail,Water_Point,MKT_Approve,Cancel_By,Cancel_Description,Vps_Acknowledge,MKT_Acknowledge,Payin,Bill_To_no,Bill_To_name,StandardTime,Credit_Limit,Status_Pay,Demurrage,Demurrage_Money,Electricity,Shifting) "
        sql &= " VALUES(@Booking_Log,@Booking_no,@Customer_no,@Customer_name,@Vehicle_no,@Vehicle_Text,@Vehicle_LOA,@Vehicle_DWT,@Vehicle_Draft,@Vehicle_GRT,@Date_From,@Date_To,@PORT,@Vehicle_destination,@Vehicle_TypeBuy,@Remark,@Status,@Remark_VPS,@VPS_approve,@Remark_MRI,@MRI_approve,@Marketing_approve,@Product_Name,@Product_Amount,@MAgent_no,@MAgent_name,@Vehicle_CNTRY,@Lay_Time,@MKT_Product,@MKT_Custom,@MKT_Finance,@SAgent_no,@SAgent_name,@Booking_Date,@Booking_Time,@Buyer,@Seller,@File_Upload,@Product_Unit,@BunkerFO_chk,@BunkerDO_chk,@BunkerFO_Point,@BunkerDO_Point,@BunkerDetail,@Water_Point,@MKT_Approve,@Cancel_By,@Cancel_Description,@Vps_Acknowledge,@MKT_Acknowledge,@Payin,@Bill_To_no,@Bill_To_name,@StandardTime,@Credit_Limit,@Status_Pay,@Demurrage,@Demurrage_Money,@Electricity,@Shifting) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_Log", SqlDbType.NVarChar, 14).Value = Booking_Log
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 50).Value = Booking_Code
        cmd.Parameters.Add("@Customer_name", SqlDbType.NVarChar, 200).Value = Booking_name
        cmd.Parameters.Add("@Vehicle_no", SqlDbType.NVarChar, 10).Value = Vehicle_no
        cmd.Parameters.Add("@Vehicle_Text", SqlDbType.NVarChar, 200).Value = Vehicle_Text
        cmd.Parameters.Add("@Vehicle_LOA", SqlDbType.NVarChar, 10).Value = Vehicle_LOA
        cmd.Parameters.Add("@Vehicle_DWT", SqlDbType.NVarChar, 10).Value = Vehicle_DWT
        cmd.Parameters.Add("@Vehicle_Draft", SqlDbType.NVarChar, 10).Value = Vehicle_Draft
        cmd.Parameters.Add("@Vehicle_GRT", SqlDbType.NVarChar, 10).Value = Vehicle_GRT
        cmd.Parameters.Add("@Date_From", SqlDbType.NVarChar, 12).Value = Date_From
        cmd.Parameters.Add("@Date_To", SqlDbType.NVarChar, 12).Value = Date_To
        cmd.Parameters.Add("@PORT", SqlDbType.NVarChar, 1).Value = PORT
        cmd.Parameters.Add("@Vehicle_destination", SqlDbType.NVarChar, 1).Value = Vehicle_destination
        cmd.Parameters.Add("@Vehicle_TypeBuy", SqlDbType.NVarChar, 1).Value = Vehicle_TypeBuy
        cmd.Parameters.Add("@Remark", SqlDbType.Text).Value = Remark
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status
        cmd.Parameters.Add("@Remark_VPS", SqlDbType.Text).Value = Remark_VPS
        cmd.Parameters.Add("@VPS_approve", SqlDbType.NVarChar, 50).Value = VPS_approve
        cmd.Parameters.Add("@Remark_MRI", SqlDbType.Text).Value = Remark_MRI
        cmd.Parameters.Add("@MRI_approve", SqlDbType.NVarChar, 50).Value = MRI_approve
        cmd.Parameters.Add("@Marketing_approve", SqlDbType.NVarChar, 50).Value = Marketing_approve
        cmd.Parameters.Add("@Product_Name", SqlDbType.NVarChar, 200).Value = Product_Name
        cmd.Parameters.Add("@Product_Amount", SqlDbType.NVarChar, 10).Value = Product_Amount
        cmd.Parameters.Add("@MAgent_no", SqlDbType.NVarChar, 10).Value = MAgent_no
        cmd.Parameters.Add("@MAgent_name", SqlDbType.NVarChar, 200).Value = MAgent_name
        cmd.Parameters.Add("@Vehicle_CNTRY", SqlDbType.NVarChar, 2).Value = Vehicle_CNTRY
        cmd.Parameters.Add("@Lay_Time", SqlDbType.NVarChar, 20).Value = Lay_Time
        cmd.Parameters.Add("@MKT_Product", SqlDbType.NVarChar, 1).Value = MKT_Product
        cmd.Parameters.Add("@MKT_Custom", SqlDbType.NVarChar, 1).Value = MKT_Custom
        cmd.Parameters.Add("@MKT_Finance", SqlDbType.NVarChar, 1).Value = MKT_Finance
        cmd.Parameters.Add("@SAgent_no", SqlDbType.NVarChar, 10).Value = SAgent_no
        cmd.Parameters.Add("@SAgent_name", SqlDbType.NVarChar, 200).Value = SAgent_name
        cmd.Parameters.Add("@Booking_Date", SqlDbType.NVarChar, 12).Value = Booking_Date
        cmd.Parameters.Add("@Booking_Time", SqlDbType.NVarChar, 5).Value = Booking_Time
        cmd.Parameters.Add("@Buyer", SqlDbType.NVarChar, 250).Value = Buyer
        cmd.Parameters.Add("@Seller", SqlDbType.NVarChar, 250).Value = Seller
        cmd.Parameters.Add("@File_Upload", SqlDbType.NVarChar, 100).Value = File_Upload
        cmd.Parameters.Add("@Product_Unit", SqlDbType.NVarChar, 50).Value = Product_Unit
        cmd.Parameters.Add("@BunkerFO_chk", SqlDbType.NVarChar, 1).Value = BunkerFO_chk
        cmd.Parameters.Add("@BunkerDO_chk", SqlDbType.NVarChar, 1).Value = BunkerDo_Chk
        cmd.Parameters.Add("@BunkerFO_Point", SqlDbType.NVarChar, 10).Value = BunkerFO_Point
        cmd.Parameters.Add("@BunkerDO_Point", SqlDbType.NVarChar, 10).Value = BunkerDO_Point
        cmd.Parameters.Add("@BunkerDetail", SqlDbType.NVarChar, 500).Value = BunkerDetail
        cmd.Parameters.Add("@Water_Point", SqlDbType.NVarChar, 10).Value = Water_Point
        cmd.Parameters.Add("@MKT_Approve", SqlDbType.NVarChar, 50).Value = MKT_Approve
        cmd.Parameters.Add("@Cancel_By", SqlDbType.NVarChar, 50).Value = Cancel_By
        cmd.Parameters.Add("@Cancel_Description", SqlDbType.NVarChar, 500).Value = Cancel_Description
        cmd.Parameters.Add("@Vps_Acknowledge", SqlDbType.NVarChar, 50).Value = Vps_Acknowledge
        cmd.Parameters.Add("@MKT_Acknowledge", SqlDbType.NVarChar, 50).Value = MKT_Acknowledge
        cmd.Parameters.Add("@Payin", SqlDbType.NVarChar, 1).Value = Payin
        cmd.Parameters.Add("@Bill_To_no", SqlDbType.NVarChar, 10).Value = Bill_To_no
        cmd.Parameters.Add("@Bill_To_name", SqlDbType.NVarChar, 200).Value = Bill_To_name
        cmd.Parameters.Add("@StandardTime", SqlDbType.NVarChar, 10).Value = StandardTime
        cmd.Parameters.Add("@Credit_Limit", SqlDbType.NVarChar, 1).Value = Credit_Limit
        cmd.Parameters.Add("@Status_Pay", SqlDbType.NVarChar, 1).Value = Status_Pay
        cmd.Parameters.Add("@Demurrage", SqlDbType.NVarChar, 50).Value = Demurrage
        cmd.Parameters.Add("@Demurrage_Money", SqlDbType.NVarChar, 1).Value = Demurrage_Money
        cmd.Parameters.Add("@Electricity", SqlDbType.NVarChar, 10).Value = Electricity
        cmd.Parameters.Add("@Shifting", SqlDbType.NVarChar, 1).Value = Shifting

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function
    Public Function DeleteBookingProduct(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Booking_Product WHERE Booking_no=@Booking_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBookingProduct(ByVal Booking_no As String, ByVal Product_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Booking_Product WHERE Booking_no=@Booking_no and Product_no Not in (" & Product_no & ") "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_Wharf(ByVal Booking_no As String, ByVal BookingWharf As String, ByVal Date_From As String, ByVal Date_To As String, ByVal TimeStart As String, ByVal TimeEnd As String, ByVal Remark As String, ByVal User_Create As String, ByVal DateStart As String, ByVal DateEnd As String, ByVal Confirm_Time As String, ByVal Shift_Booking As String, ByVal Note As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "INSERT BookingWharf(Booking_no,BookingWharf,Date_From,Date_To,TimeStart,TimeEnd,Remark,User_Create,DateStart,DateEnd,Confirm_Time,Shift_Booking,Note) "
        sql &= " VALUES(@Booking_no,@BookingWharf,@Date_From,@Date_To,@TimeStart,@TimeEnd,@Remark,@User_Create,@DateStart,@DateEnd,@Confirm_Time,@Shift_Booking,@Note) "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@BookingWharf", SqlDbType.NVarChar, 5).Value = BookingWharf
        cmd.Parameters.Add("@Date_From", SqlDbType.NVarChar, 12).Value = Date_From
        cmd.Parameters.Add("@Date_To", SqlDbType.NVarChar, 12).Value = Date_To
        cmd.Parameters.Add("@TimeStart", SqlDbType.NVarChar, 5).Value = TimeStart
        cmd.Parameters.Add("@TimeEnd", SqlDbType.NVarChar, 5).Value = TimeEnd
        cmd.Parameters.Add("@Remark", SqlDbType.Text).Value = Remark
        cmd.Parameters.Add("@User_Create", SqlDbType.NVarChar, 50).Value = User_Create
        cmd.Parameters.Add("@DateStart", SqlDbType.NVarChar, 12).Value = DateStart
        cmd.Parameters.Add("@DateEnd", SqlDbType.NVarChar, 12).Value = DateEnd
        cmd.Parameters.Add("@Confirm_Time", SqlDbType.NVarChar, 1).Value = Confirm_Time
        cmd.Parameters.Add("@Shift_Booking", SqlDbType.NVarChar, 10).Value = Shift_Booking
        cmd.Parameters.Add("@Note", SqlDbType.NVarChar, 2000).Value = Note
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_Shifting(ByVal e As String, ByVal Booking_no As String, ByVal Shifting_ID As String, ByVal BookingWharf As String, ByVal DateStart As String, ByVal DateEnd As String, ByVal TimeStart As String, ByVal TimeEnd As String, ByVal Remark As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If e = "UPDATE" Then
            sql = "UPDATE Booking_Shifting SET " & vbCrLf
            sql &= "Booking_no = @Booking_no," & vbCrLf
            sql &= "Shifting_ID = @Shifting_ID," & vbCrLf
            sql &= "BookingWharf = @BookingWharf," & vbCrLf
            sql &= "DateStart = @DateStart," & vbCrLf
            sql &= "DateEnd = @DateEnd," & vbCrLf
            sql &= "TimeStart = @TimeStart," & vbCrLf
            sql &= "TimeEnd = @TimeEnd," & vbCrLf
            sql &= "Remark = @Remark" & vbCrLf
            sql &= "WHERE Booking_no = @Booking_no" & vbCrLf
            sql &= "AND Shifting_ID = @Shifting_ID"
        Else
            sql = "INSERT Booking_Shifting(Booking_no, Shifting_ID, BookingWharf, DateStart, DateEnd, TimeStart, TimeEnd, Remark)" & vbCrLf
            sql &= "VALUES(@Booking_no, @Shifting_ID, @BookingWharf, @DateStart, @DateEnd, @TimeStart, @TimeEnd, @Remark)"
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Shifting_ID", SqlDbType.NVarChar, 10).Value = Shifting_ID
        cmd.Parameters.Add("@BookingWharf", SqlDbType.NVarChar, 5).Value = BookingWharf
        cmd.Parameters.Add("@DateStart", SqlDbType.NVarChar, 12).Value = DateStart
        cmd.Parameters.Add("@DateEnd", SqlDbType.NVarChar, 12).Value = DateEnd
        cmd.Parameters.Add("@TimeStart", SqlDbType.NVarChar, 5).Value = TimeStart
        cmd.Parameters.Add("@TimeEnd", SqlDbType.NVarChar, 5).Value = TimeEnd
        cmd.Parameters.Add("@Remark", SqlDbType.Text).Value = Remark
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertMaintenance_Wharf(ByVal Maintenance_id As String, ByVal Maintenance_Create As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "INSERT Maintenance_Wharf(Maintenance_id,Maintenance_Create) "
        sql &= " VALUES(@Maintenance_id,@Maintenance_Create) "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Maintenance_id", SqlDbType.NVarChar, 10).Value = Maintenance_id
        cmd.Parameters.Add("@Maintenance_Create", SqlDbType.NVarChar, 50).Value = Maintenance_Create
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBookingTariff_Acutal_Same_Billing(ByVal MATERIAL As String, ByVal Booking_no As String, ByVal Text_line As String, ByVal Unit As String, ByVal Count As String, ByVal MAT_Default As String, ByVal KBETR As String, ByVal KONWA As String, ByVal MAT_Relation As String, ByVal MAT_Compute As String, ByVal MAT_Free As String, ByVal data1 As String, ByVal data2 As String, ByVal data3 As String, ByVal data4 As String, ByVal New_Old As String, ByVal Owner As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "INSERT BookingTariff_Actual(MATERIAL,Booking_no,Text_line,Unit,Count,MAT_Default,KBETR,KONWA,MAT_Relation,MAT_Compute,MAT_Free,data1,data2,data3,data4,New_Old,Owner) "
        sql &= " VALUES(@MATERIAL,@Booking_no,@Text_line,@Unit,@Count,@MAT_Default,@KBETR,@KONWA,@MAT_Relation,@MAT_Compute,@MAT_Free,@data1,@data2,@data3,@data4,@New_Old,@Owner) "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Text_line", SqlDbType.NVarChar, 200).Value = Text_line
        cmd.Parameters.Add("@Unit", SqlDbType.NVarChar, 50).Value = Unit
        cmd.Parameters.Add("@Count", SqlDbType.NVarChar, 50).Value = Count
        cmd.Parameters.Add("@MAT_Default", SqlDbType.NVarChar, 1).Value = MAT_Default
        cmd.Parameters.Add("@KBETR", SqlDbType.NVarChar, 50).Value = KBETR
        cmd.Parameters.Add("@KONWA", SqlDbType.NVarChar, 50).Value = KONWA
        cmd.Parameters.Add("@MAT_Relation", SqlDbType.NVarChar, 1).Value = MAT_Relation
        cmd.Parameters.Add("@MAT_Compute", SqlDbType.NVarChar, 1).Value = MAT_Compute
        cmd.Parameters.Add("@MAT_Free", SqlDbType.NVarChar, 1).Value = MAT_Free
        cmd.Parameters.Add("@data1", SqlDbType.NVarChar, 50).Value = data1
        cmd.Parameters.Add("@data2", SqlDbType.NVarChar, 50).Value = data2
        cmd.Parameters.Add("@data3", SqlDbType.NVarChar, 50).Value = data3
        cmd.Parameters.Add("@data4", SqlDbType.NVarChar, 50).Value = data4
        cmd.Parameters.Add("@New_Old", SqlDbType.NVarChar, 1).Value = New_Old
        cmd.Parameters.Add("@Owner", SqlDbType.NVarChar, 10).Value = Owner
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertComfirm_Booking(ByVal Booking_no As String, ByVal _Date As String, ByVal _Time As String, ByVal Confirm_By As String, ByVal Confirm_DateTime As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "INSERT ConfirmActual(Booking_no,_Date,_Time,Confirm_By,Confirm_DateTime) "
        sql &= " VALUES(@Booking_no,@_Date,@_Time,@Confirm_By,@Confirm_DateTime) "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@_Date", SqlDbType.NVarChar, 15).Value = _Date
        cmd.Parameters.Add("@_Time", SqlDbType.NVarChar, 5).Value = _Time
        cmd.Parameters.Add("@Confirm_By", SqlDbType.NVarChar, 50).Value = Confirm_By
        cmd.Parameters.Add("@Confirm_DateTime", SqlDbType.NVarChar, 50).Value = Confirm_DateTime
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertActual_Data_Backup_For_Billing(ByVal MATERIAL As String, ByVal Booking_no As String, ByVal Text_line As String, ByVal Unit As String, ByVal Count As String, ByVal MAT_Default As String, ByVal KBETR As String, ByVal KONWA As String, ByVal MAT_Relation As String, ByVal MAT_Compute As String, ByVal MAT_Free As String, ByVal data1 As String, ByVal data2 As String, ByVal data3 As String, ByVal data4 As String, ByVal New_Old As String, ByVal chk As String, ByVal Owner As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "INSERT Actual_Data_Backup_For_Billing(MATERIAL,Booking_no,Text_line,Unit,Count,MAT_Default,KBETR,KONWA,MAT_Relation,MAT_Compute,MAT_Free,data1,data2,data3,data4,New_Old,chk,Owner) "
        sql &= " VALUES(@MATERIAL,@Booking_no,@Text_line,@Unit,@Count,@MAT_Default,@KBETR,@KONWA,@MAT_Relation,@MAT_Compute,@MAT_Free,@data1,@data2,@data3,@data4,@New_Old,@chk,@Owner) "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Text_line", SqlDbType.NVarChar, 200).Value = Text_line
        cmd.Parameters.Add("@Unit", SqlDbType.NVarChar, 50).Value = Unit
        cmd.Parameters.Add("@Count", SqlDbType.NVarChar, 50).Value = Count
        cmd.Parameters.Add("@MAT_Default", SqlDbType.NVarChar, 1).Value = MAT_Default
        cmd.Parameters.Add("@KBETR", SqlDbType.NVarChar, 50).Value = KBETR
        cmd.Parameters.Add("@KONWA", SqlDbType.NVarChar, 50).Value = KONWA
        cmd.Parameters.Add("@MAT_Relation", SqlDbType.NVarChar, 1).Value = MAT_Relation
        cmd.Parameters.Add("@MAT_Compute", SqlDbType.NVarChar, 1).Value = MAT_Compute
        cmd.Parameters.Add("@MAT_Free", SqlDbType.NVarChar, 1).Value = MAT_Free
        cmd.Parameters.Add("@data1", SqlDbType.NVarChar, 50).Value = data1
        cmd.Parameters.Add("@data2", SqlDbType.NVarChar, 50).Value = data2
        cmd.Parameters.Add("@data3", SqlDbType.NVarChar, 50).Value = data3
        cmd.Parameters.Add("@data4", SqlDbType.NVarChar, 50).Value = data4
        cmd.Parameters.Add("@New_Old", SqlDbType.NVarChar, 1).Value = New_Old
        cmd.Parameters.Add("@chk", SqlDbType.NVarChar, 1).Value = chk
        cmd.Parameters.Add("@Owner", SqlDbType.NVarChar, 10).Value = Owner
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateFor_Shifting(ByVal Booking_no As String, ByVal ShiftingFrom As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " UPDATE Booking SET " & vbCrLf
        sql &= " Status = 'MO' ,  Marketing_approve = 'Shifting" & ShiftingFrom & "' , vps_approve = 'Shifting" & ShiftingFrom & "' , mri_approve = 'Shifting" & ShiftingFrom & "' " & vbCrLf
        sql &= " WHERE Booking_no = @Booking_no " & vbCrLf

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBooking_Product(ByVal Booking_no As String, ByVal Product_no As String, ByVal Product_name As String, ByVal Group_no As String, ByVal Group_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " UPDATE Booking_Product SET " & vbCrLf
        sql &= " Product_no = @Product_no , Product_name = @Product_name , Group_no = @Group_no , Group_name = @Group_name " & vbCrLf
        sql &= " WHERE Booking_no = @Booking_no " & vbCrLf

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 200).Value = Product_name
        cmd.Parameters.Add("@Group_no", SqlDbType.NVarChar, 10).Value = Group_no
        cmd.Parameters.Add("@Group_name", SqlDbType.NVarChar, 200).Value = Group_name
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_Product(ByVal E As String, ByVal Booking_no As String, ByVal Product_no As String, ByVal Product_name As String, ByVal Product_Amount As String, ByVal Product_Event As String, ByVal Group_no As String, ByVal Group_name As String, ByVal Product_Buyer_no As String, ByVal Product_Buyer_name As String, ByVal Product_Seller_no As String, ByVal Product_Seller_name As String, ByVal LoadDestination As String, ByVal DischDestination As String, ByVal DestinationShow As String, ByVal Product_Description As String, ByVal Product_Unit As String, ByVal Owner_Product_no As String, ByVal Owner_Product_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (E = "EDIT") Then
            sql = "UPDATE Booking_Product SET "
            sql &= " Product_Amount = @Product_Amount, Product_Event = @Product_Event,Product_Description = @Product_Description,DestinationShow = @DestinationShow,Group_no = @Group_no"
            sql &= " ,Group_name =@Group_name,Product_Buyer_no =@Product_Buyer_no,Product_Buyer_name=@Product_Buyer_name,Product_Seller_no=@Product_Seller_no,Product_Seller_name=@Product_Seller_name,Product_Unit=@Product_Unit"
            sql &= " ,LoadDestination=@LoadDestination,DischDestination=@DischDestination"
            sql &= " WHERE Booking_no = @Booking_no"
            sql &= " AND Product_no = @Product_no "
            sql &= " AND Owner_Product_no=@Owner_Product_no "

        Else
            sql = "INSERT Booking_Product(Booking_no,Product_no,Product_name,Product_Amount,Product_Event,Product_Description,DestinationShow,Group_no,Group_name,Product_Buyer_no,Product_Buyer_name,Product_Seller_no,Product_Seller_name,Product_Unit,LoadDestination,DischDestination,Owner_Product_no,Owner_Product_name) "
            sql &= " VALUES(@Booking_no,@Product_no,@Product_name,@Product_Amount,@Product_Event,@Product_Description,@DestinationShow,@Group_no,@Group_name,@Product_Buyer_no,@Product_Buyer_name,@Product_Seller_no,@Product_Seller_name,@Product_Unit,@LoadDestination,@DischDestination,@Owner_Product_no,@Owner_Product_name)"
        End If



        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 200).Value = Product_name
        cmd.Parameters.Add("@Product_Amount", SqlDbType.NVarChar, 10).Value = Product_Amount
        cmd.Parameters.Add("@Product_Event", SqlDbType.NVarChar, 1).Value = Product_Event
        cmd.Parameters.Add("@Product_Description", SqlDbType.NVarChar, 200).Value = Product_Description
        cmd.Parameters.Add("@Group_no", SqlDbType.NVarChar, 10).Value = Group_no
        cmd.Parameters.Add("@Group_name", SqlDbType.NVarChar, 200).Value = Group_name
        cmd.Parameters.Add("@Product_Buyer_no", SqlDbType.NVarChar, 10).Value = Product_Buyer_no
        cmd.Parameters.Add("@Product_Buyer_name", SqlDbType.NVarChar, 200).Value = Product_Buyer_name
        cmd.Parameters.Add("@Product_Seller_no", SqlDbType.NVarChar, 10).Value = Product_Seller_no
        cmd.Parameters.Add("@Product_Seller_name", SqlDbType.NVarChar, 200).Value = Product_Seller_name
        cmd.Parameters.Add("@DestinationShow", SqlDbType.NVarChar, 200).Value = DestinationShow
        cmd.Parameters.Add("@LoadDestination", SqlDbType.NVarChar, 200).Value = LoadDestination
        cmd.Parameters.Add("@Product_Unit", SqlDbType.NVarChar, 5).Value = Product_Unit
        cmd.Parameters.Add("@DischDestination", SqlDbType.NVarChar, 200).Value = DischDestination
        cmd.Parameters.Add("@Owner_Product_no", SqlDbType.NVarChar, 200).Value = Owner_Product_no
        cmd.Parameters.Add("@Owner_Product_name", SqlDbType.NVarChar, 200).Value = Owner_Product_name
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateProduct_Owner(ByVal Booking_no As String, ByVal Product_no As String, ByVal Owner_Product_no As String, ByVal Owner_Product_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "UPDATE Booking_Product "
        sql &= " SET Owner_Product_no = @Owner_Product_no ,Owner_Product_name = @Owner_Product_name "
        sql &= " WHERE Booking_no = @Booking_no AND Product_no = @Product_no "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Owner_Product_no", SqlDbType.NVarChar, 10).Value = Owner_Product_no
        cmd.Parameters.Add("@Owner_Product_name", SqlDbType.NVarChar, 200).Value = Owner_Product_name
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function


    Public Function InsertBooking_Upload(ByVal Booking_no As String, ByVal File_nameGuid As String, ByVal File_name As String, ByVal File_type As String, ByVal File_ContentType As String, ByVal Type_Upload As String, ByVal Description As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "INSERT Booking_Upload(Booking_no,File_nameGuid,File_name,File_Type,File_ContentType,Upload_Type,Description) "
        sql &= " VALUES(@Booking_no,@File_nameGuid,@File_name,@File_Type,@File_ContentType,@Type_Upload,@Description) "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@File_nameGuid", SqlDbType.NVarChar, 50).Value = File_nameGuid
        cmd.Parameters.Add("@File_name", SqlDbType.NVarChar, 200).Value = File_name
        cmd.Parameters.Add("@File_Type", SqlDbType.NVarChar, 10).Value = File_type
        cmd.Parameters.Add("@File_ContentType", SqlDbType.NVarChar, 50).Value = File_ContentType
        cmd.Parameters.Add("@Type_Upload", SqlDbType.NVarChar, 30).Value = Type_Upload
        cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 500).Value = Description
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    'Public Function InsertBooking_Product_Log(ByVal Booking_log As String, ByVal Booking_no As String, ByVal Product_no As String, ByVal Product_name As String, ByVal Product_Amount As String, ByVal Product_Event As String, ByVal Group_no As String, ByVal Group_name As String, ByVal Product_Buyer_no As String, ByVal Product_Buyer_name As String, ByVal Product_Seller_no As String, ByVal Product_Seller_name As String, ByVal LoadDestination As String, ByVal DischDestination As String, ByVal DestinationShow As String, ByVal Product_Description As String, ByVal Product_Unit As String, ByVal Owner_Product_no As String, ByVal Owner_Product_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
    '    Dim adap As New SqlDataAdapter()
    '    Dim sql As String = ""
    '    Dim ret As Integer = 0

    '    sql = "INSERT Booking_Product_Log(Booking_Log,Booking_no,Product_no,Product_name,Product_Amount,Product_Event,Product_Description,DestinationShow,Group_no,Group_name,Product_Buyer_no,Product_Buyer_name,Product_Seller_no,Product_Seller_name,Product_Unit,LoadDestination,DischDestination,Owner_Product_no,Owner_Product_name) "
    '    sql &= " VALUES(@Booking_Log,@Booking_no,@Product_no,@Product_name,@Product_Amount,@Product_Event,@Product_Description,@DestinationShow,@Group_no,@Group_name,@Product_Buyer_no,@Product_Buyer_name,@Product_Seller_no,@Product_Seller_name,@Product_Unit,@LoadDestination,@DischDestination,@Owner_Product_no,@Owner_Product_name) "


    '    Dim cmd As New SqlCommand(sql, conn)
    '    If Not (tran Is Nothing) Then
    '        cmd.Connection = conn
    '        cmd.Transaction = tran
    '    End If
    '    cmd.Parameters.Clear()
    '    cmd.Parameters.Add("@Booking_Log", SqlDbType.NVarChar, 14).Value = Booking_log
    '    cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
    '    cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
    '    cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 200).Value = Product_name
    '    cmd.Parameters.Add("@Product_Amount", SqlDbType.NVarChar, 10).Value = Product_Amount
    '    cmd.Parameters.Add("@Product_Event", SqlDbType.NVarChar, 1).Value = Product_Event
    '    cmd.Parameters.Add("@Product_Description", SqlDbType.NVarChar, 200).Value = Product_Description
    '    cmd.Parameters.Add("@Group_no", SqlDbType.NVarChar, 10).Value = Group_no
    '    cmd.Parameters.Add("@Group_name", SqlDbType.NVarChar, 200).Value = Group_name
    '    cmd.Parameters.Add("@Product_Buyer_no", SqlDbType.NVarChar, 10).Value = Product_Buyer_no
    '    cmd.Parameters.Add("@Product_Buyer_name", SqlDbType.NVarChar, 200).Value = Product_Buyer_name
    '    cmd.Parameters.Add("@Product_Seller_no", SqlDbType.NVarChar, 10).Value = Product_Seller_no
    '    cmd.Parameters.Add("@Product_Seller_name", SqlDbType.NVarChar, 200).Value = Product_Seller_name
    '    cmd.Parameters.Add("@DestinationShow", SqlDbType.NVarChar, 200).Value = DestinationShow
    '    cmd.Parameters.Add("@LoadDestination", SqlDbType.NVarChar, 200).Value = LoadDestination
    '    cmd.Parameters.Add("@Product_Unit", SqlDbType.NVarChar, 5).Value = Product_Unit
    '    cmd.Parameters.Add("@DischDestination", SqlDbType.NVarChar, 200).Value = DischDestination
    '    cmd.Parameters.Add("@Owner_Product_no", SqlDbType.NVarChar, 200).Value = Owner_Product_no
    '    cmd.Parameters.Add("@Owner_Product_name", SqlDbType.NVarChar, 200).Value = Owner_Product_name
    '    ret = cmd.ExecuteNonQuery()
    '    cmd.Dispose()
    '    Return ret
    'End Function

    Public Function DeleteBookingTariff(ByVal Booking_no As String, ByVal Owner_Product_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM BookingTariff WHERE Booking_no=@Booking_no And Owner = @Owner "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Owner", SqlDbType.NVarChar, 10).Value = Owner_Product_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBooking_Upload(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Booking_Upload WHERE Booking_no=@Booking_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteSAP_Temp_Estimate(ByVal Booking_no As String, ByVal Owner_product As String, ByVal Material As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Temp_Estimate WHERE Booking_no = @Booking_no  "
        If (Owner_product <> "") Then
            sql &= " And Owner_Product = @Owner_Product "
        End If
        If (Material <> "") Then
            sql &= "  And Material = @Material "
        End If

        Try
            Material = CInt(Material).ToString("000000000000000000")
        Catch ex As Exception

        End Try
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Owner_Product", SqlDbType.NVarChar, 10).Value = Owner_product
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBookingWharfMaintenance(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM BookingWharf WHERE Booking_no = @Booking_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteActual_Data_Backup_For_Billing(ByVal Booking_no As String, ByVal Owner As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        ''**** เก็บ Log Actual
        sql = "INSERT INTO Actual_Data_Backup_For_Billing_Backup " & vbCrLf
        sql &= "SELECT " & vbCrLf
        sql &= "RoundNo =  ISNULL((SELECT MAX(RoundNo) FROM Actual_Data_Backup_For_Billing_Backup WHERE Booking_no = A.Booking_no), 0) + 1" & vbCrLf
        sql &= ", *" & vbCrLf
        'sql &= ",[MATERIAL],[Booking_no],[Text_line],[Unit],[Count],[MAT_Default],[KBETR],[KONWA],[MAT_Relation],[MAT_Compute],[MAT_Free],[data1],[data2],[data3],[data4],[New_Old],[Owner],[chk]" & vbCrLf
        sql &= "FROM Actual_Data_Backup_For_Billing A" & vbCrLf
        sql &= "WHERE Booking_no = @Booking_no " & vbCrLf
        If (Owner <> "") Then
            sql &= "AND Owner = @Owner " & vbCrLf
        End If

        sql &= "DELETE FROM Actual_Data_Backup_For_Billing WHERE Booking_no = @Booking_no "
        If (Owner <> "") Then
            sql &= " AND Owner = @Owner "
        End If
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        If (Owner <> "") Then
            cmd.Parameters.Add("@Owner", SqlDbType.NVarChar, 10).Value = Owner
        End If
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function
	
    Public Function InsertSAP_Temp_Estimate(ByVal Booking_no As String, ByVal Material As String, ByVal MAT_NAME As String, ByVal name As String, ByVal data1 As String, ByVal data2 As String, ByVal data3 As String, ByVal data4 As String, ByVal Owner_Product As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Temp_Estimate(Booking_no,Material,MAT_NAME,name,data1,data2,data3,data4,Owner_Product) "
        sql &= " VALUES (@Booking_no,@Material,@MAT_NAME,@name,@data1,@data2,@data3,@data4,@Owner_Product)"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        Try
            Material = CInt(Material).ToString("000000000000000000")
        Catch ex As Exception

        End Try
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material
        cmd.Parameters.Add("@MAT_NAME", SqlDbType.NVarChar, 200).Value = MAT_NAME
        cmd.Parameters.Add("@name", SqlDbType.NVarChar, 200).Value = name
        cmd.Parameters.Add("@data1", SqlDbType.NVarChar, 50).Value = data1
        cmd.Parameters.Add("@data2", SqlDbType.NVarChar, 50).Value = data2
        cmd.Parameters.Add("@data3", SqlDbType.NVarChar, 50).Value = data3
        cmd.Parameters.Add("@data4", SqlDbType.NVarChar, 50).Value = data4
        cmd.Parameters.Add("@Owner_Product", SqlDbType.NVarChar, 10).Value = Owner_Product
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBookingTariff(ByVal MATERIAL As String, ByVal Booking_no As String, ByVal Text_line As String, ByVal Unit As String, ByVal Count As String, ByVal MAT_Default As String, ByVal KBETR As String, ByVal KONWA As String, ByVal MAT_Relation As String, ByVal MAT_Compute As String, ByVal MAT_Free As String, ByVal Owner As String, ByVal SumTotal As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "INSERT BookingTariff(MATERIAL,Booking_no,Text_line,Unit,Count,MAT_Default,KBETR,KONWA,MAT_Relation,MAT_Compute,MAT_Free,Owner,SumTotal) "
        sql &= " VALUES(@MATERIAL,@Booking_no,@Text_line,@Unit,@Count,@MAT_Default,@KBETR,@KONWA,@MAT_Relation,@MAT_Compute,@MAT_Free,@Owner,@SumTotal)"


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Text_line", SqlDbType.NVarChar, 200).Value = Text_line
        cmd.Parameters.Add("@Unit", SqlDbType.NVarChar, 20).Value = Unit
        cmd.Parameters.Add("@Count", SqlDbType.NVarChar, 5).Value = Count
        cmd.Parameters.Add("@MAT_Default", SqlDbType.NVarChar, 10).Value = MAT_Default
        cmd.Parameters.Add("@KBETR", SqlDbType.NVarChar, 5).Value = KBETR
        cmd.Parameters.Add("@KONWA", SqlDbType.NVarChar, 200).Value = KONWA
        cmd.Parameters.Add("@MAT_Relation", SqlDbType.NVarChar, 1).Value = MAT_Relation
        cmd.Parameters.Add("@MAT_Compute", SqlDbType.NVarChar, 1).Value = MAT_Compute
        cmd.Parameters.Add("@MAT_Free", SqlDbType.NVarChar, 1).Value = MAT_Free
        cmd.Parameters.Add("@Owner", SqlDbType.NVarChar, 10).Value = Owner
        cmd.Parameters.Add("@SumTotal", SqlDbType.NVarChar, 20).Value = SumTotal
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateTariffFree(ByVal MATERIAL As String, ByVal Booking_no As String, ByVal Owner_Product_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "UPDATE BookingTariff SET MAT_Free = 'Y' WHERE Booking_no = @Booking_no AND MATERIAL In (" & MATERIAL & ") AND Owner = @Owner "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Owner", SqlDbType.NVarChar, 10).Value = Owner_Product_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateTariffOwnerBillTo(ByVal Booking_no As String, ByVal Owner_product_no As String, ByVal Billing_no As String, ByVal Billing_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "UPDATE Booking_Product SET Billing_no = @Billing_no,Billing_name = @Billing_name WHERE Booking_no = @Booking_no AND Owner_product_no = @Owner_product_no "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Owner_product_no", SqlDbType.NVarChar, 10).Value = Owner_product_no
        cmd.Parameters.Add("@Billing_no", SqlDbType.NVarChar, 10).Value = Billing_no
        cmd.Parameters.Add("@Billing_name", SqlDbType.NVarChar, 500).Value = Billing_name
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateTariffOwner(ByVal Booking_no As String, ByVal Owner_product_no As String, ByVal Type_Pay As String, ByVal Billing_no As String, ByVal Billing_name As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "UPDATE Booking_Product SET Type_Pay = @Type_Pay ,Billing_no = @Billing_no,Billing_name = @Billing_name,Status = @Status WHERE Booking_no = @Booking_no AND Owner_product_no = @Owner_product_no "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Owner_product_no", SqlDbType.NVarChar, 10).Value = Owner_product_no
        cmd.Parameters.Add("@Type_Pay", SqlDbType.NVarChar, 1).Value = Type_Pay
        cmd.Parameters.Add("@Billing_no", SqlDbType.NVarChar, 10).Value = Billing_no
        cmd.Parameters.Add("@Billing_name", SqlDbType.NVarChar, 500).Value = Billing_name
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 2).Value = Status
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateTariffFree_LOG(ByVal MATERIAL As String, ByVal Booking_no As String, ByVal Booking_Log As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "UPDATE BookingTariff_Log SET MAT_Free = 'Y' WHERE Booking_Log = @Booking_Log  AND Booking_no = @Booking_no AND MATERIAL In (" & MATERIAL & ") "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Booking_Log", SqlDbType.NVarChar, 14).Value = Booking_Log
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBookingTariff_Log(ByVal Booking_log As String, ByVal MATERIAL As String, ByVal Booking_no As String, ByVal Text_line As String, ByVal Unit As String, ByVal Count As String, ByVal MAT_Default As String, ByVal KBETR As String, ByVal KONWA As String, ByVal MAT_Relation As String, ByVal MAT_Compute As String, ByVal MAT_Free As String, ByVal Owner As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT BookingTariff_Log(Booking_Log,MATERIAL,Booking_no,Text_line,Unit,Count,MAT_Default,KBETR,KONWA,MAT_Relation,MAT_Compute,MAT_Free,Owner) "
        sql &= " VALUES(@Booking_Log,@MATERIAL,@Booking_no,@Text_line,@Unit,@Count,@MAT_Default,@KBETR,@KONWA,@MAT_Relation,@MAT_Compute,@MAT_Free,@Owner)"


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_Log", SqlDbType.NVarChar, 14).Value = Booking_log
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Text_line", SqlDbType.NVarChar, 200).Value = Text_line
        cmd.Parameters.Add("@Unit", SqlDbType.NVarChar, 20).Value = Unit
        cmd.Parameters.Add("@Count", SqlDbType.NVarChar, 5).Value = Count
        cmd.Parameters.Add("@MAT_Default", SqlDbType.NVarChar, 10).Value = MAT_Default
        cmd.Parameters.Add("@KBETR", SqlDbType.NVarChar, 5).Value = KBETR
        cmd.Parameters.Add("@KONWA", SqlDbType.NVarChar, 200).Value = KONWA
        cmd.Parameters.Add("@MAT_Relation", SqlDbType.NVarChar, 1).Value = MAT_Relation
        cmd.Parameters.Add("@MAT_Compute", SqlDbType.NVarChar, 1).Value = MAT_Compute
        cmd.Parameters.Add("@MAT_Free", SqlDbType.NVarChar, 1).Value = MAT_Free
        cmd.Parameters.Add("@Owner", SqlDbType.NVarChar, 10).Value = Owner
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateCustomer(ByVal Customer_no As String, ByVal Name1 As String, ByVal Name2 As String, ByVal Name3 As String, ByVal Street As String, ByVal STR_SUPPL3 As String, ByVal LOCATION As String, ByVal District As String, ByVal City As String, ByVal Postal_Code As String, ByVal Country_Key As String, ByVal Default_Pay As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " UPDATE Customer SET " & vbCrLf
        sql &= "  NAME1=@NAME1,NAME2=@NAME2,NAME3=@NAME3" & vbCrLf
        sql &= " ,STREET=@STREET,STR_SUPPL3=@STR_SUPPL3,LOCATION=@LOCATION,District=@District,City=@City,Postal_Code=@Postal_Code" & vbCrLf
        sql &= " ,Country_Key=@Country_Key,Default_Pay=@Default_Pay" & vbCrLf
        sql &= " WHERE Customer_no =@Customer_no " & vbCrLf

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 10).Value = Customer_no
        cmd.Parameters.Add("@NAME1", SqlDbType.NVarChar, 40).Value = Name1
        cmd.Parameters.Add("@NAME2", SqlDbType.NVarChar, 40).Value = Name2
        cmd.Parameters.Add("@NAME3", SqlDbType.NVarChar, 40).Value = Name3
        cmd.Parameters.Add("@STREET", SqlDbType.NVarChar, 60).Value = Street
        cmd.Parameters.Add("@STR_SUPPL3", SqlDbType.NVarChar, 40).Value = STR_SUPPL3
        cmd.Parameters.Add("@LOCATION", SqlDbType.NVarChar, 40).Value = LOCATION
        cmd.Parameters.Add("@District", SqlDbType.NVarChar, 40).Value = District
        cmd.Parameters.Add("@City", SqlDbType.NVarChar, 40).Value = City
        cmd.Parameters.Add("@Postal_Code", SqlDbType.NVarChar, 10).Value = Postal_Code
        cmd.Parameters.Add("@Country_Key", SqlDbType.NVarChar, 3).Value = Country_Key
        ' cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 12).Value = Password
        cmd.Parameters.Add("@Default_Pay", SqlDbType.NVarChar, 1).Value = Default_Pay

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateCustomerPayin(ByVal Customer_no As String, ByVal Default_Pay As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " UPDATE Customer SET " & vbCrLf
        sql &= " Default_Pay=@Default_Pay" & vbCrLf
        sql &= " WHERE Customer_no =@Customer_no " & vbCrLf

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 10).Value = Customer_no
        cmd.Parameters.Add("@Default_Pay", SqlDbType.NVarChar, 1).Value = Default_Pay

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertCustomer(ByVal Customer_no As String, ByVal Name1 As String, ByVal Name2 As String, ByVal Name3 As String, ByVal Street As String, ByVal STR_SUPPL3 As String, ByVal LOCATION As String, ByVal District As String, ByVal City As String, ByVal Postal_Code As String, ByVal Country_Key As String, ByVal Default_Pay As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Customer(Customer_no,NAME1,NAME2,NAME3,STREET,STR_SUPPL3,LOCATION,District,City,Postal_Code,Country_Key,Default_Pay) "
        sql &= " VALUES(@Customer_no,@NAME1,@NAME2,@NAME3,@STREET,@STR_SUPPL3,@LOCATION,@District,@City,@Postal_Code,@Country_Key,@Default_Pay)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 10).Value = Customer_no
        cmd.Parameters.Add("@NAME1", SqlDbType.NVarChar, 40).Value = Name1
        cmd.Parameters.Add("@NAME2", SqlDbType.NVarChar, 40).Value = Name2
        cmd.Parameters.Add("@NAME3", SqlDbType.NVarChar, 40).Value = Name3
        cmd.Parameters.Add("@STREET", SqlDbType.NVarChar, 60).Value = Street
        cmd.Parameters.Add("@STR_SUPPL3", SqlDbType.NVarChar, 40).Value = STR_SUPPL3
        cmd.Parameters.Add("@LOCATION", SqlDbType.NVarChar, 40).Value = LOCATION
        cmd.Parameters.Add("@District", SqlDbType.NVarChar, 40).Value = District
        cmd.Parameters.Add("@City", SqlDbType.NVarChar, 40).Value = City
        cmd.Parameters.Add("@Postal_Code", SqlDbType.NVarChar, 10).Value = Postal_Code
        cmd.Parameters.Add("@Country_Key", SqlDbType.NVarChar, 3).Value = Country_Key
        ' cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 12).Value = Password
        cmd.Parameters.Add("@Default_Pay", SqlDbType.NVarChar, 1).Value = Default_Pay

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateCustomerBillTo(ByVal BillTo As String, ByVal Customer_no As String, ByVal Name1 As String, ByVal Name2 As String, ByVal Name3 As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Customer_Billto(Bill_to,Customer_no,NAME1,NAME2,NAME3) "
        sql &= " VALUES(@Bill_to,@Customer_no,@NAME1,@NAME2,@NAME3)"

        sql = " UPDATE Customer_Billto SET " & vbCrLf
        sql &= " NAME1 = @NAME1,NAME2=@NAME2,NAME3=@NAME3" & vbCrLf
        sql &= " WHERE Bill_to=@Bill_to AND Customer_no=@Customer_no" & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Bill_to", SqlDbType.NVarChar, 10).Value = BillTo
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 10).Value = Customer_no
        cmd.Parameters.Add("@NAME1", SqlDbType.NVarChar, 40).Value = Name1
        cmd.Parameters.Add("@NAME2", SqlDbType.NVarChar, 40).Value = Name2
        cmd.Parameters.Add("@NAME3", SqlDbType.NVarChar, 40).Value = Name3
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertCustomerBillTo(ByVal BillTo As String, ByVal Customer_no As String, ByVal Name1 As String, ByVal Name2 As String, ByVal Name3 As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Customer_Billto(Bill_to,Customer_no,NAME1,NAME2,NAME3) "
        sql &= " VALUES(@Bill_to,@Customer_no,@NAME1,@NAME2,@NAME3)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Bill_to", SqlDbType.NVarChar, 10).Value = BillTo
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 10).Value = Customer_no
        cmd.Parameters.Add("@NAME1", SqlDbType.NVarChar, 40).Value = Name1
        cmd.Parameters.Add("@NAME2", SqlDbType.NVarChar, 40).Value = Name2
        cmd.Parameters.Add("@NAME3", SqlDbType.NVarChar, 40).Value = Name3
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertIportNumber(ByVal iport_number As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Iport_Number(Number,Call_Date) "
        sql &= " VALUES(@Number,@Call_Date)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        Dim Number As String = iport_number.Split("-")(1)
        Dim Call_Date As String = iport_number.Split("-")(0)
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Number", SqlDbType.NVarChar, 3).Value = Number
        cmd.Parameters.Add("@Call_Date", SqlDbType.NVarChar, 8).Value = Call_Date
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_Credit_limit(ByVal Booking_no As String, ByVal iport_number As String, ByVal sale_order As String, ByVal Release_By As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Booking_Credit_limit(Booking_no,iport_Number,Sale_Order,Release_By,Ralease_Time) "
        sql &= " VALUES(@Booking_no,@iport_Number,@Sale_Order,@Release_By,@Ralease_Time)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@iport_Number", SqlDbType.NVarChar, 12).Value = iport_number
        cmd.Parameters.Add("@Sale_Order", SqlDbType.NVarChar, 20).Value = sale_order
        cmd.Parameters.Add("@Release_By", SqlDbType.NVarChar, 50).Value = Release_By
        cmd.Parameters.Add("@Ralease_Time", SqlDbType.NVarChar, 20).Value = Date.Now.ToString("dd MMM yyyy HH:mm")
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATESale_Order(ByVal Booking_no As String, ByVal Iport_no As String, ByVal EX_SALES_NO As String, ByVal EX_BILL_NO As String, ByVal EX_BUKRS As String, ByVal EX_BELNR As String, ByVal EX_GJAHR As String, ByVal Billing_Date As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE SAP_Sale_Order SET "
        sql &= " Credit_Limit = 'Y' "
        sql &= " ,EX_SALES_NO = @EX_SALES_NO,EX_BILL_NO=@EX_BILL_NO,EX_BUKRS=@EX_BUKRS,EX_BELNR=@EX_BELNR,EX_GJAHR = @EX_GJAHR,Billing_Date = @Billing_Date  "
        sql &= " WHERE Booking_no = @Booking_no AND Iport_no = @Iport_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Iport_no", SqlDbType.NVarChar, 12).Value = Iport_no
        cmd.Parameters.Add("@EX_SALES_NO", SqlDbType.NVarChar, 10).Value = EX_SALES_NO
        cmd.Parameters.Add("@EX_BILL_NO", SqlDbType.NVarChar, 10).Value = EX_BILL_NO
        cmd.Parameters.Add("@EX_BUKRS", SqlDbType.NVarChar, 50).Value = EX_BUKRS
        cmd.Parameters.Add("@EX_BELNR", SqlDbType.NVarChar, 50).Value = EX_BELNR
        cmd.Parameters.Add("@EX_GJAHR", SqlDbType.NVarChar, 50).Value = EX_GJAHR
        cmd.Parameters.Add("@Billing_Date", SqlDbType.NVarChar, 8).Value = Billing_Date
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATESale_OrderPay(ByVal Booking_no As String, ByVal EX_BILL_NO As String, ByVal EX_BUKRS As String, ByVal EX_BELNR As String, ByVal EX_GJAHR As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE SAP_Sale_Order SET "
        sql &= " Credit_Limit = 'Y' "
        sql &= " ,EX_BUKRS=@EX_BUKRS,EX_BELNR=@EX_BELNR,EX_GJAHR = @EX_GJAHR "
        sql &= " WHERE Booking_no = @Booking_no AND EX_BILL_NO = @EX_BILL_NO "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@EX_BILL_NO", SqlDbType.NVarChar, 10).Value = EX_BILL_NO
        cmd.Parameters.Add("@EX_BUKRS", SqlDbType.NVarChar, 50).Value = EX_BUKRS
        cmd.Parameters.Add("@EX_BELNR", SqlDbType.NVarChar, 50).Value = EX_BELNR
        cmd.Parameters.Add("@EX_GJAHR", SqlDbType.NVarChar, 50).Value = EX_GJAHR
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATEBooking_Credit_limit(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking SET "
        sql &= " Credit_Limit = 'Y' "
        sql &= " WHERE Booking_no = @Booking_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBookingTariff_Actual(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " Insert INTO BookingTariff_Actual(MATERIAL,Booking_no,Text_line,Unit,Count,MAT_Default,KBETR,KONWA,MAT_Relation,MAT_Compute,MAT_Free,data1,data2,data3,data4,New_Old,Owner) " & vbCrLf
        sql &= " select Distinct B.MATERIAL,B.Booking_no,B.Text_line,B.Unit,B.Count,B.MAT_Default,B.KBETR,B.KONWA,B.MAT_Relation,B.MAT_Compute,B.MAT_Free " & vbCrLf
        sql &= "   ,T.data1, case Convert(Decimal(18,2),T.data2) * Convert(Decimal(18,2),T.data3) when T.data4 then T.data2 when '0' then T.data2 else T.data4 end as data2,case Convert(Decimal(18,2),T.data2) * Convert(Decimal(18,2),T.data3) when T.data4  then T.data3 When '0' then T.data1 else '1' end as data3,T.data4,'O' as New_Old ,B.Owner" & vbCrLf
        sql &= " from BookingTariff B,(select Booking_no,Material,MAT_NAME,data1,data2, case data3 when '' then '0' else data3 end as data3,data4,Owner_Product from Temp_Estimate) as T  " & vbCrLf
        sql &= " where B.Booking_no = @Booking_no " & vbCrLf
        sql &= " and B.Booking_no = T.Booking_no " & vbCrLf
        sql &= " and B.MATERIAL = T.MATERIAL " & vbCrLf
        sql &= " and T.data4 <> '0.00'" & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBookingTariff_Actual(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " Delete FROM BookingTariff_Actual " & vbCrLf
        sql &= " where Booking_no = @Booking_no " & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBookingTariff_Actual2(ByVal Booking_no As String, ByVal MATERIAL As String, ByVal Text_line As String, ByVal Unit As String, ByVal Count As String, ByVal MAT_Default As String, ByVal KBETR As String, ByVal KONWA As String, ByVal MAT_Relation As String, ByVal MAT_Compute As String, ByVal MAT_Free As String, ByVal data1 As String, ByVal data2 As String, ByVal data3 As String, ByVal data4 As String, ByVal New_Old As String, ByVal Owner As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " Insert INTO BookingTariff_Actual(MATERIAL,Booking_no,Text_line,Unit,Count,MAT_Default,KBETR,KONWA,MAT_Relation,MAT_Compute,MAT_Free,data1,data2,data3,data4,New_Old,Owner) " & vbCrLf
        sql &= " VALUES (@MATERIAL,@Booking_no,@Text_line,@Unit,@Count,@MAT_Default,@KBETR,@KONWA,@MAT_Relation,@MAT_Compute,@MAT_Free,@data1,@data2,@data3,@data4,@New_Old,@Owner) " & vbCrLf

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@Text_line", SqlDbType.NVarChar, 200).Value = Text_line
        cmd.Parameters.Add("@Unit", SqlDbType.NVarChar, 20).Value = Unit
        cmd.Parameters.Add("@Count", SqlDbType.NVarChar, 10).Value = Count
        cmd.Parameters.Add("@MAT_Default", SqlDbType.NVarChar, 1).Value = MAT_Default
        cmd.Parameters.Add("@KBETR", SqlDbType.Decimal, 11, 2).Value = KBETR
        cmd.Parameters.Add("@KONWA", SqlDbType.NVarChar, 5).Value = KONWA
        cmd.Parameters.Add("@MAT_Relation", SqlDbType.NVarChar, 1).Value = MAT_Relation
        cmd.Parameters.Add("@MAT_Compute", SqlDbType.NVarChar, 1).Value = MAT_Compute
        cmd.Parameters.Add("@MAT_Free", SqlDbType.NVarChar, 1).Value = MAT_Free
        cmd.Parameters.Add("@data1", SqlDbType.NVarChar, 50).Value = data1
        cmd.Parameters.Add("@data2", SqlDbType.NVarChar, 50).Value = data2
        cmd.Parameters.Add("@data3", SqlDbType.NVarChar, 50).Value = data3
        cmd.Parameters.Add("@data4", SqlDbType.NVarChar, 50).Value = data4
        cmd.Parameters.Add("@New_Old", SqlDbType.NVarChar, 1).Value = New_Old
        cmd.Parameters.Add("@Owner", SqlDbType.NVarChar, 10).Value = Owner
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertSAP_INCOME(ByVal Booking_no As String, ByVal IM_IPORTNUM As String, ByVal IM_CUSTOMER As String, ByVal DOC_DATE As String, ByVal PSTNG_DATE As String, ByVal BUPLA As String, ByVal HEADER_TXT As String, ByVal GL_ACCOUNT As String, ByVal AMOUNT As String, ByVal VALUE_DATE As String, ByVal ITEM_TEXT As String, ByVal EX_BUKRS As String, ByVal EX_BELNR As String, ByVal EX_GJAHR As String, ByVal WHT As String, ByVal Type_Pay As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_INCOME(Booking_no,IM_IPORTNUM,IM_CUSTOMER,DOC_DATE,PSTNG_DATE,BUPLA,HEADER_TXT,GL_ACCOUNT,AMOUNT,VALUE_DATE,ITEM_TEXT,EX_BUKRS,EX_BELNR,EX_GJAHR,WHT,Type_Pay) "
        sql &= " VALUES(@Booking_no,@IM_IPORTNUM,@IM_CUSTOMER,@DOC_DATE,@PSTNG_DATE,@BUPLA,@HEADER_TXT,@GL_ACCOUNT,@AMOUNT,@VALUE_DATE,@ITEM_TEXT,@EX_BUKRS,@EX_BELNR,@EX_GJAHR,@WHT,@Type_Pay) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@IM_IPORTNUM", SqlDbType.NVarChar, 12).Value = IM_IPORTNUM
        cmd.Parameters.Add("@IM_CUSTOMER", SqlDbType.NVarChar, 10).Value = IM_CUSTOMER
        cmd.Parameters.Add("@DOC_DATE", SqlDbType.NVarChar, 8).Value = DOC_DATE
        cmd.Parameters.Add("@PSTNG_DATE", SqlDbType.NVarChar, 8).Value = PSTNG_DATE
        cmd.Parameters.Add("@BUPLA", SqlDbType.NVarChar, 4).Value = BUPLA
        cmd.Parameters.Add("@HEADER_TXT", SqlDbType.NVarChar, 25).Value = HEADER_TXT
        cmd.Parameters.Add("@GL_ACCOUNT", SqlDbType.NVarChar, 10).Value = GL_ACCOUNT
        cmd.Parameters.Add("@AMOUNT", SqlDbType.NVarChar, 20).Value = AMOUNT
        cmd.Parameters.Add("@VALUE_DATE", SqlDbType.NVarChar, 8).Value = VALUE_DATE
        cmd.Parameters.Add("@ITEM_TEXT", SqlDbType.NVarChar, 50).Value = ITEM_TEXT
        cmd.Parameters.Add("@EX_BUKRS", SqlDbType.NVarChar, 4).Value = EX_BUKRS
        cmd.Parameters.Add("@EX_BELNR", SqlDbType.NVarChar, 10).Value = EX_BELNR
        cmd.Parameters.Add("@EX_GJAHR", SqlDbType.NVarChar, 4).Value = EX_GJAHR
        cmd.Parameters.Add("@WHT", SqlDbType.NVarChar, 20).Value = WHT
        cmd.Parameters.Add("@Type_Pay", SqlDbType.NVarChar, 1).Value = Type_Pay
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()

        Return ret
    End Function

    Public Function InsertSAP_INCOME_CLEARING(ByVal IM_IPORTNUM As String, ByVal COMP_CODE As String, ByVal FISC_YEAR As String, ByVal AC_DOC_NO As String, ByVal BLART As String, ByVal WHTAMT As String, ByVal WAERS As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_INCOME_CLEARING(IM_IPORTNUM,COMP_CODE,FISC_YEAR,AC_DOC_NO,BLART,WHTAMT,WAERS) "
        sql &= " VALUES(@IM_IPORTNUM,@COMP_CODE,@FISC_YEAR,@AC_DOC_NO,@BLART,@WHTAMT,@WAERS) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@IM_IPORTNUM", SqlDbType.NVarChar, 12).Value = IM_IPORTNUM
        cmd.Parameters.Add("@COMP_CODE", SqlDbType.NVarChar, 4).Value = COMP_CODE
        cmd.Parameters.Add("@FISC_YEAR", SqlDbType.NVarChar, 4).Value = FISC_YEAR
        cmd.Parameters.Add("@AC_DOC_NO", SqlDbType.NVarChar, 10).Value = AC_DOC_NO
        cmd.Parameters.Add("@BLART", SqlDbType.NVarChar, 2).Value = BLART
        cmd.Parameters.Add("@WHTAMT", SqlDbType.NVarChar, 15).Value = WHTAMT
        cmd.Parameters.Add("@WAERS", SqlDbType.NVarChar, 5).Value = WAERS

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()

        Return ret
    End Function

    Public Function InsertSAP_Advanced_Payment(ByVal Booking_no As String, ByVal Iport_no As String, ByVal Gl_Account As String, ByVal Item_Text As String, ByVal Value_Date As String, ByVal Bupla As String, ByVal Doc_Date As String, ByVal Header_Txt As String, ByVal Pstng_Date As String, ByVal Amount As String, ByVal Vat As String, ByVal Ex_Bukrs As String, ByVal Ex_Gjahr As String, ByVal Ex_Belnr As String, ByVal WHT As String, ByVal Type_Pay As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_Advanced_Payment(Booking_no,Iport_no,Gl_Account,Item_Text,Value_Date,Bupla,Doc_Date,Header_Txt,Pstng_Date,Amount,Vat,Ex_Bukrs,Ex_Gjahr,Ex_Belnr,WHT,Type_Pay) "
        sql &= " VALUES(@Booking_no,@Iport_no,@Gl_Account,@Item_Text,@Value_Date,@Bupla,@Doc_Date,@Header_Txt,@Pstng_Date,@Amount,@Vat,@Ex_Bukrs,@Ex_Gjahr,@Ex_Belnr,@WHT,@Type_Pay) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Iport_no", SqlDbType.NVarChar, 12).Value = Iport_no
        cmd.Parameters.Add("@Gl_Account", SqlDbType.NVarChar, 50).Value = Gl_Account
        cmd.Parameters.Add("@Item_Text", SqlDbType.NVarChar, 200).Value = Item_Text
        cmd.Parameters.Add("@Value_Date", SqlDbType.NVarChar, 8).Value = Value_Date
        cmd.Parameters.Add("@Bupla", SqlDbType.NVarChar, 4).Value = Bupla
        cmd.Parameters.Add("@Doc_Date", SqlDbType.NVarChar, 8).Value = Doc_Date
        cmd.Parameters.Add("@Header_Txt", SqlDbType.NVarChar, 200).Value = Header_Txt
        cmd.Parameters.Add("@Pstng_Date", SqlDbType.NVarChar, 50).Value = Pstng_Date
        cmd.Parameters.Add("@Amount", SqlDbType.NVarChar, 50).Value = Amount
        cmd.Parameters.Add("@Vat", SqlDbType.NVarChar, 10).Value = Vat
        cmd.Parameters.Add("@Ex_Bukrs", SqlDbType.NVarChar, 50).Value = Ex_Bukrs
        cmd.Parameters.Add("@Ex_Gjahr", SqlDbType.NVarChar, 50).Value = Ex_Gjahr
        cmd.Parameters.Add("@Ex_Belnr", SqlDbType.NVarChar, 50).Value = Ex_Belnr
        cmd.Parameters.Add("@WHT", SqlDbType.NVarChar, 20).Value = WHT
        cmd.Parameters.Add("@Type_Pay", SqlDbType.NVarChar, 1).Value = Type_Pay

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()

        Return ret
    End Function

    Public Function InsertSAP_Advanced_Payment_Material(ByVal Iport_no As String, ByVal Customer As String, ByVal Amount As String, ByVal Item_Text As String, ByVal Material As String, ByVal Price As String, ByVal Quantity As String, ByVal Unit As String, ByVal Wht_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_Advanced_Payment_Material(Iport_no,Customer,Amount,Item_Text,Material,Price,Quantity,Unit,Wht_Code) "
        sql &= " VALUES(@Iport_no,@Customer,@Amount,@Item_Text,@Material,@Price,@Quantity,@Unit,@Wht_Code) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Iport_no", SqlDbType.NVarChar, 12).Value = Iport_no
        cmd.Parameters.Add("@Customer", SqlDbType.NVarChar, 10).Value = Customer
        cmd.Parameters.Add("@Amount", SqlDbType.NVarChar, 20).Value = Amount
        cmd.Parameters.Add("@Item_Text", SqlDbType.NVarChar, 200).Value = Item_Text
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material
        cmd.Parameters.Add("@Price", SqlDbType.NVarChar, 20).Value = Price
        cmd.Parameters.Add("@Quantity", SqlDbType.NVarChar, 20).Value = Quantity
        cmd.Parameters.Add("@Unit", SqlDbType.NVarChar, 20).Value = Unit
        cmd.Parameters.Add("@Wht_Code", SqlDbType.NVarChar, 20).Value = Wht_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()

        Return ret
    End Function

    Public Function InsertSaleOrder(ByVal Booking_no As String, ByVal Iport_no As String, ByVal Doc_Type As String, ByVal Req_Date_H As String, ByVal Sold_To As String, ByVal Bill_To As String, ByVal Ship_Name As String, ByVal Division As String, ByVal EX_SALES_NO As String, ByVal EX_BILL_NO As String, ByVal Credit_Limit As String, ByVal EX_BUKRS As String, ByVal EX_BELNR As String, ByVal EX_GJAHR As String, ByVal Billing_Date As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_Sale_Order(Booking_no,Iport_no,Doc_Type,Req_Date_H,Sold_To,Bill_To,Ship_Name,EX_SALES_NO,EX_BILL_NO,Division,Credit_Limit,EX_BUKRS,EX_BELNR,EX_GJAHR,Billing_Date) "
        sql &= " VALUES(@Booking_no,@Iport_no,@Doc_Type,@Req_Date_H,@Sold_To,@Bill_To,@Ship_Name,@EX_SALES_NO,@EX_BILL_NO,@Division,@Credit_Limit,@EX_BUKRS,@EX_BELNR,@EX_GJAHR,@Billing_Date)"
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Iport_no", SqlDbType.NVarChar, 12).Value = Iport_no
        cmd.Parameters.Add("@Doc_Type", SqlDbType.NVarChar, 4).Value = Doc_Type
        cmd.Parameters.Add("@Req_Date_H", SqlDbType.NVarChar, 8).Value = Req_Date_H
        cmd.Parameters.Add("@Sold_To", SqlDbType.NVarChar, 10).Value = Sold_To
        cmd.Parameters.Add("@Bill_To", SqlDbType.NVarChar, 10).Value = Bill_To
        cmd.Parameters.Add("@Ship_Name", SqlDbType.NVarChar, 200).Value = Ship_Name
        cmd.Parameters.Add("@EX_SALES_NO", SqlDbType.NVarChar, 10).Value = EX_SALES_NO
        cmd.Parameters.Add("@EX_BILL_NO", SqlDbType.NVarChar, 10).Value = EX_BILL_NO
        cmd.Parameters.Add("@Credit_Limit", SqlDbType.NVarChar, 1).Value = Credit_Limit
        cmd.Parameters.Add("@EX_BUKRS", SqlDbType.NVarChar, 50).Value = EX_BUKRS
        cmd.Parameters.Add("@EX_BELNR", SqlDbType.NVarChar, 50).Value = EX_BELNR
        cmd.Parameters.Add("@EX_GJAHR", SqlDbType.NVarChar, 50).Value = EX_GJAHR
        cmd.Parameters.Add("@Division", SqlDbType.NVarChar, 2).Value = Division
        cmd.Parameters.Add("@Billing_Date", SqlDbType.NVarChar, 8).Value = Billing_Date

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()

        Return ret
    End Function

    Public Function InsertSAP_Sale_Order_Material(ByVal Iport_no As String, ByVal Material As String, ByVal Plant As String, ByVal Target_Qty As String, ByVal Target_Qu As String, ByVal Cond_Type As String, ByVal Discount As String, ByVal Amount As String, ByVal Condvalue As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_Sale_Order_Material(Iport_no,Material,Plant,Target_Qty,Target_Qu,Cond_Type,Discount,Amount,Condvalue) "
        sql &= " VALUES(@Iport_no,@Material,@Plant,@Target_Qty,@Target_Qu,@Cond_Type,@Discount,@Amount,@Condvalue) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Iport_no", SqlDbType.NVarChar, 12).Value = Iport_no
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material
        cmd.Parameters.Add("@Plant", SqlDbType.NVarChar, 4).Value = Plant
        cmd.Parameters.Add("@Target_Qty", SqlDbType.NVarChar, 20).Value = Target_Qty
        cmd.Parameters.Add("@Target_Qu", SqlDbType.NVarChar, 20).Value = Target_Qu
        cmd.Parameters.Add("@Cond_Type", SqlDbType.NVarChar, 20).Value = Cond_Type
        cmd.Parameters.Add("@Discount", SqlDbType.NVarChar, 20).Value = Discount
        cmd.Parameters.Add("@Amount", SqlDbType.NVarChar, 20).Value = Amount
        cmd.Parameters.Add("@Condvalue", SqlDbType.NVarChar, 20).Value = Condvalue

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateSAP_Sale_Order_Material(ByVal Iport_no As String, ByVal Material As String, ByVal Plant As String, ByVal Target_Qty As String, ByVal Target_Qu As String, ByVal Cond_Type As String, ByVal Discount As String, ByVal Amount As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " UPDATE SAP_Sale_Order_Material SET " & vbCrLf
        sql &= " Plant = @Plant , Target_Qty = @Target_Qty , Target_Qu = @Target_Qu " & vbCrLf
        sql &= " ,Cond_Type = @Cond_Type,Discount = @Discount,Amount=@Amount " & vbCrLf
        sql &= " Where Iport_no = @Iport_no and Material = @Material " & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Iport_no", SqlDbType.NVarChar, 12).Value = Iport_no
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material
        cmd.Parameters.Add("@Plant", SqlDbType.NVarChar, 4).Value = Plant
        cmd.Parameters.Add("@Target_Qty", SqlDbType.NVarChar, 20).Value = Target_Qty
        cmd.Parameters.Add("@Target_Qu", SqlDbType.NVarChar, 20).Value = Target_Qu
        cmd.Parameters.Add("@Cond_Type", SqlDbType.NVarChar, 20).Value = Cond_Type
        cmd.Parameters.Add("@Discount", SqlDbType.NVarChar, 20).Value = Discount
        cmd.Parameters.Add("@Amount", SqlDbType.NVarChar, 20).Value = Amount

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteSAP_Sale_Order_Material(ByVal Iport_no As String, ByVal Material As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " DELETE FROM SAP_Sale_Order_Material  " & vbCrLf
        sql &= " Where Iport_no = @Iport_no and Material = @Material " & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Iport_no", SqlDbType.NVarChar, 12).Value = Iport_no
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertSAP_SALE_ORDER_CHANGE(ByVal IM_SALES_ORDER As String, ByVal UPDATEFLAG As String, ByVal MATERIAL As String, ByVal TARGET_QTY As String, ByVal TARGET_QU As String, ByVal PLANT As String, ByVal COND_TYPE As String, ByVal COND_AMOUNT As String, ByVal DISC_TYPE As String, ByVal DISC_AMOUNT As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_SALE_ORDER_CHANGE(IM_SALES_ORDER,UPDATEFLAG,MATERIAL,TARGET_QTY,TARGET_QU,PLANT,COND_TYPE,COND_AMOUNT,DISC_TYPE,DISC_AMOUNT) "
        sql &= " VALUES(@IM_SALES_ORDER,@UPDATEFLAG,@MATERIAL,@TARGET_QTY,@TARGET_QU,@PLANT,@COND_TYPE,@COND_AMOUNT,@DISC_TYPE,@DISC_AMOUNT) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@IM_SALES_ORDER", SqlDbType.NVarChar, 10).Value = IM_SALES_ORDER
        cmd.Parameters.Add("@UPDATEFLAG", SqlDbType.NVarChar, 1).Value = UPDATEFLAG
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@TARGET_QTY", SqlDbType.NVarChar, 20).Value = TARGET_QTY
        cmd.Parameters.Add("@TARGET_QU", SqlDbType.NVarChar, 3).Value = TARGET_QU
        cmd.Parameters.Add("@PLANT", SqlDbType.NVarChar, 4).Value = PLANT
        cmd.Parameters.Add("@COND_TYPE", SqlDbType.NVarChar, 4).Value = COND_TYPE
        cmd.Parameters.Add("@COND_AMOUNT", SqlDbType.NVarChar, 20).Value = COND_AMOUNT
        cmd.Parameters.Add("@DISC_TYPE", SqlDbType.NVarChar, 4).Value = DISC_TYPE
        cmd.Parameters.Add("@DISC_AMOUNT", SqlDbType.NVarChar, 20).Value = DISC_AMOUNT

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertSAP_CNDN_REQUEST(ByVal Booking_no As String, ByVal IM_IPORTNUM As String, ByVal IM_REF_DOC As String, ByVal IM_DOCTYPE As String, ByVal IM_REASON As String, ByVal IM_VALDATE As String, ByVal EX_SALES_NO As String, ByVal sold_To As String, ByVal RELEASE As String, ByVal Old_Iport_no As String, ByVal conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_CNDN_REQUEST(Booking_no,IM_IPORTNUM,IM_REF_DOC,IM_DOCTYPE,IM_REASON,IM_VALDATE,EX_SALES_NO,sold_To,RELEASE,Old_Iport_no) "
        sql &= " VALUES(@Booking_no,@IM_IPORTNUM,@IM_REF_DOC,@IM_DOCTYPE,@IM_REASON,@IM_VALDATE,@EX_SALES_NO,@sold_To,@RELEASE,@Old_Iport_no) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@IM_IPORTNUM", SqlDbType.NVarChar, 12).Value = IM_IPORTNUM
        cmd.Parameters.Add("@IM_REF_DOC", SqlDbType.NVarChar, 10).Value = IM_REF_DOC
        cmd.Parameters.Add("@IM_DOCTYPE", SqlDbType.NVarChar, 4).Value = IM_DOCTYPE
        cmd.Parameters.Add("@IM_REASON", SqlDbType.NVarChar, 3).Value = IM_REASON
        cmd.Parameters.Add("@IM_VALDATE", SqlDbType.NVarChar, 8).Value = IM_VALDATE
        cmd.Parameters.Add("@EX_SALES_NO", SqlDbType.NVarChar, 10).Value = EX_SALES_NO
        cmd.Parameters.Add("@sold_To", SqlDbType.NVarChar, 10).Value = sold_To
        cmd.Parameters.Add("@RELEASE", SqlDbType.NVarChar, 1).Value = RELEASE
        cmd.Parameters.Add("@Old_Iport_no", SqlDbType.NVarChar, 12).Value = Old_Iport_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATESAP_CNDN_REQUEST(ByVal Booking_no As String, ByVal IM_IPORTNUM As String, ByVal Release_By As String, ByVal CNDN_Bill As String, ByVal ReleaseDate As Date, ByVal conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE SAP_CNDN_REQUEST SET "
        sql &= " RELEASE = 'Y' , Release_By = @Release_By , Release_Time = @Release_Time , CNDN_Bill = @CNDN_Bill "
        sql &= " WHERE Booking_no = @Booking_no and IM_IPORTNUM = @IM_IPORTNUM "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@IM_IPORTNUM", SqlDbType.NVarChar, 12).Value = IM_IPORTNUM
        cmd.Parameters.Add("@Release_By", SqlDbType.NVarChar, 50).Value = Release_By
        cmd.Parameters.Add("@Release_Time", SqlDbType.NVarChar, 20).Value = Date.Now.ToString("dd MMM yyyy HH:mm")
        cmd.Parameters.Add("@CNDN_Bill", SqlDbType.NVarChar, 10).Value = CNDN_Bill

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertSAP_CNDN_ITEM_REQUEST(ByVal IM_IPORTNUM As String, ByVal MATERIAL As String, ByVal PLANT As String, ByVal TARGET_QTY As String, ByVal TARGET_QU As String, ByVal COND_TYPE As String, ByVal AMOUNT As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_CNDN_ITEM_REQUEST(IM_IPORTNUM,MATERIAL,PLANT,TARGET_QTY,TARGET_QU,COND_TYPE,AMOUNT) "
        sql &= " VALUES(@IM_IPORTNUM,@MATERIAL,@PLANT,@TARGET_QTY,@TARGET_QU,@COND_TYPE,@AMOUNT) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@IM_IPORTNUM", SqlDbType.NVarChar, 12).Value = IM_IPORTNUM
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@PLANT", SqlDbType.NVarChar, 4).Value = PLANT
        cmd.Parameters.Add("@TARGET_QTY", SqlDbType.NVarChar, 20).Value = TARGET_QTY
        cmd.Parameters.Add("@TARGET_QU", SqlDbType.NVarChar, 3).Value = TARGET_QU
        cmd.Parameters.Add("@COND_TYPE", SqlDbType.NVarChar, 4).Value = COND_TYPE
        cmd.Parameters.Add("@AMOUNT", SqlDbType.NVarChar, 13).Value = AMOUNT

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertSAP_Table_MESSAGE(ByVal Iport_no As String, ByVal RFC As String, ByVal TYPE As String, ByVal ID As String, ByVal NUMBER As String, ByVal MESSAGE As String, ByVal LOG_NO As String, ByVal LOG_MSG_NO As String, ByVal MESSAGE_V1 As String, ByVal MESSAGE_V2 As String, ByVal MESSAGE_V3 As String, ByVal MESSAGE_V4 As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SAP_Table_MESSAGE(Iport_no,RFC,TYPE,ID,NUMBER,MESSAGE,LOG_NO,LOG_MSG_NO,MESSAGE_V1,MESSAGE_V2,MESSAGE_V3,MESSAGE_V4) "
        sql &= " VALUES(@Iport_no,@RFC,@TYPE,@ID,@NUMBER,@MESSAGE,@LOG_NO,@LOG_MSG_NO,@MESSAGE_V1,@MESSAGE_V2,@MESSAGE_V3,@MESSAGE_V4) "
        Dim cmd As New SqlCommand(sql, conn)

        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Iport_no", SqlDbType.NVarChar, 12).Value = Iport_no
        cmd.Parameters.Add("@RFC", SqlDbType.NVarChar, 100).Value = RFC
        cmd.Parameters.Add("@TYPE", SqlDbType.NVarChar, 1).Value = TYPE
        cmd.Parameters.Add("@ID", SqlDbType.NVarChar, 20).Value = ID
        cmd.Parameters.Add("@NUMBER", SqlDbType.NVarChar, 3).Value = NUMBER
        cmd.Parameters.Add("@MESSAGE", SqlDbType.NVarChar, 220).Value = MESSAGE
        cmd.Parameters.Add("@LOG_NO", SqlDbType.NVarChar, 20).Value = LOG_NO
        cmd.Parameters.Add("@LOG_MSG_NO", SqlDbType.NVarChar, 6).Value = LOG_MSG_NO
        cmd.Parameters.Add("@MESSAGE_V1", SqlDbType.NVarChar, 50).Value = MESSAGE_V1
        cmd.Parameters.Add("@MESSAGE_V2", SqlDbType.NVarChar, 50).Value = MESSAGE_V2
        cmd.Parameters.Add("@MESSAGE_V3", SqlDbType.NVarChar, 50).Value = MESSAGE_V3
        cmd.Parameters.Add("@MESSAGE_V4", SqlDbType.NVarChar, 50).Value = MESSAGE_V4
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()

        Return ret
    End Function

    Public Function InsertMENU(ByVal eventSQL As String, ByVal Menu_no As String, ByVal Menu_name As String, ByVal Mode As String, ByVal Path As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT MENU(Menu_no,Menu_name,Mode,Path) "
            sql &= " VALUES(@Menu_no,@Menu_name,@Mode,@Path)"
        Else
            sql = "UPDATE MENU SET Menu_name = @Menu_name , Mode = @Mode , Path = @Path "
            sql &= " WHERE Menu_no = @Menu_no "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Menu_no", SqlDbType.NVarChar, 10).Value = Menu_no
        cmd.Parameters.Add("@Menu_name", SqlDbType.NVarChar, 50).Value = Menu_name
        cmd.Parameters.Add("@Mode", SqlDbType.NVarChar, 100).Value = Mode
        cmd.Parameters.Add("@Path", SqlDbType.NVarChar, 500).Value = Path
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertProduct(ByVal eventSQL As String, ByVal Product_no As String, ByVal Product_name As String, ByVal Group_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Product(Product_no,Product_name,Group_no) "
            sql &= " VALUES(@Product_no,@Product_name,@Group_no)"
        Else
            sql = "UPDATE Product SET Product_name = @Product_name , Group_no = @Group_no "
            sql &= " WHERE Product_no = @Product_no "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 200).Value = Product_name
        cmd.Parameters.Add("@Group_no", SqlDbType.NVarChar, 10).Value = Group_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertOrtherService(ByVal eventSQL As String, ByVal Ots_ID As String, ByVal dayIn As String, ByVal TimeIn As String, ByVal Type_Customer As String, ByVal Customer_no As String, ByVal Customer_name As String, ByVal Bill_TO_no As String, ByVal BIll_To_name As String, ByVal City As String, ByVal District As String, ByVal Location As String, ByVal Postal_Code As String, ByVal Str_Sup As String, ByVal Street As String, ByVal Booking_no As String, ByVal PORT As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT OtherService_Head(Ots_ID,dayIn,TimeIn,Type_Customer,Customer_no,Customer_name,Bill_TO_no,BIll_To_Name,City,District,Location,Postal_Code,Str_Sup,Street,Booking_no,Status,PORT) "
            sql &= " VALUES(@Ots_ID,@dayIn,@TimeIn,@Type_Customer,@Customer_no,@Customer_name,@Bill_TO_no,@BIll_To_Name,@City,@District,@Location,@Postal_Code,@Str_Sup,@Street,@Booking_no,'N',@PORT)"
        Else
            sql = "UPDATE OtherService_Head SET Booking_no = @Booking_no, dayIn = @dayIn, TimeIn = @TimeIn,Type_Customer = @Type_Customer,Customer_no = @Customer_no,Customer_name = @Customer_name,Bill_To_no = @Bill_TO_no,BIll_To_Name = @BIll_To_Name,City = @City,District = @District,Location = @Location,Postal_Code = @Postal_Code,Str_Sup = @Str_Sup,Street = @Street , PORT = @PORT "
            sql &= " WHERE Ots_ID = @Ots_ID "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Ots_ID", SqlDbType.NVarChar, 10).Value = Ots_ID
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@dayIn", SqlDbType.NVarChar, 15).Value = dayIn
        cmd.Parameters.Add("@TimeIn", SqlDbType.NVarChar, 5).Value = TimeIn
        cmd.Parameters.Add("@Type_Customer", SqlDbType.NVarChar, 1).Value = Type_Customer
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 10).Value = Customer_no
        cmd.Parameters.Add("@Customer_name", SqlDbType.NVarChar, 200).Value = Customer_name
        cmd.Parameters.Add("@Bill_TO_no", SqlDbType.NVarChar, 10).Value = Bill_TO_no
        cmd.Parameters.Add("@BIll_To_Name", SqlDbType.NVarChar, 200).Value = BIll_To_name
        cmd.Parameters.Add("@City", SqlDbType.NVarChar, 50).Value = City
        cmd.Parameters.Add("@District", SqlDbType.NVarChar, 50).Value = District
        cmd.Parameters.Add("@Location", SqlDbType.NVarChar, 50).Value = Location
        cmd.Parameters.Add("@Postal_Code", SqlDbType.NVarChar, 50).Value = Postal_Code
        cmd.Parameters.Add("@Str_Sup", SqlDbType.NVarChar, 50).Value = Str_Sup
        cmd.Parameters.Add("@Street", SqlDbType.NVarChar, 50).Value = Street
        cmd.Parameters.Add("@PORT", SqlDbType.NVarChar, 1).Value = PORT
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertOrtherService_ITem(ByVal Ots_ID As String, ByVal Material As String, ByVal Text_line As String, ByVal Rate As String, ByVal Amount As String, ByVal Total As String, ByVal CashType As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT OtherService(Ots_ID,Material,Text_line,Rate,Amount,Total,CashType) "
        sql &= " VALUES(@Ots_ID,@Material,@Text_line,@Rate,@Amount,@Total,@CashType)"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Ots_ID", SqlDbType.NVarChar, 10).Value = Ots_ID
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material
        cmd.Parameters.Add("@Text_line", SqlDbType.NVarChar, 500).Value = Text_line
        cmd.Parameters.Add("@Rate", SqlDbType.NVarChar, 20).Value = Rate
        cmd.Parameters.Add("@Amount", SqlDbType.NVarChar, 20).Value = Amount
        cmd.Parameters.Add("@Total", SqlDbType.NVarChar, 20).Value = Total
        cmd.Parameters.Add("@CashType", SqlDbType.NVarChar, 1).Value = CashType
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertProduct_Group(ByVal eventSQL As String, ByVal Group_no As String, ByVal Group_name As String, ByVal PORT As String, ByVal StandardTime As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Product_Group(Group_no,Group_name,Group_PORT,StandardTime) "
            sql &= " VALUES(@Group_no,@Group_name,@Group_PORT,@StandardTime)"
        Else
            sql = "UPDATE Product_Group SET Group_name = @Group_name ,Group_PORT = @Group_PORT,StandardTime = @StandardTime "
            sql &= " WHERE Group_no = @Group_no "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Group_no", SqlDbType.NVarChar, 10).Value = Group_no
        cmd.Parameters.Add("@Group_name", SqlDbType.NVarChar, 200).Value = Group_name
        cmd.Parameters.Add("@Group_PORT", SqlDbType.NVarChar, 1).Value = PORT
        cmd.Parameters.Add("@StandardTime", SqlDbType.Decimal, 18, 3).Value = StandardTime
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertFacility(ByVal eventSQL As String, ByVal Facility_Code As String, ByVal Mla_Host As String, ByVal Diameter As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Facility(Facility_Code,Mla_Host,Diameter) "
            sql &= " VALUES(@Facility_Code,@Mla_Host,@Diameter)"
        Else
            sql = "UPDATE Facility SET Mla_Host = @Mla_Host , Diameter = @Diameter "
            sql &= " WHERE Facility_Code = @Facility_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Facility_Code", SqlDbType.NVarChar, 10).Value = Facility_Code
        cmd.Parameters.Add("@Mla_Host", SqlDbType.NVarChar, 400).Value = Mla_Host
        cmd.Parameters.Add("@Diameter", SqlDbType.NVarChar, 400).Value = Diameter
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function


    Public Function InsertSlop(ByVal eventSQL As String, ByVal Slop_Code As String, ByVal Slop_Name As String, ByVal Slop_Description As String, ByVal slop_Amount As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Slop_Master(Slop_Code,Slop_Name,Slop_Description) "
            sql &= " VALUES(@Slop_Code,@Slop_Name,@Slop_Description)"
        Else
            sql = "UPDATE Slop_Master SET Slop_Name = @Slop_Name , Slop_Description = @Slop_Description "
            sql &= " WHERE Slop_Code = @Slop_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Slop_Code", SqlDbType.NVarChar, 10).Value = Slop_Code
        cmd.Parameters.Add("@Slop_Name", SqlDbType.NVarChar, 200).Value = Slop_Name
        cmd.Parameters.Add("@Slop_Description", SqlDbType.NVarChar, 500).Value = Slop_Description
        cmd.Parameters.Add("@Slop_Amount", SqlDbType.NVarChar, 10).Value = slop_Amount
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Update_Slop(ByVal Slop_Code As String, ByVal Plus As String, ByVal _D As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "UPDATE Slop_Transection "
        sql &= " SET Slop_Value = convert(decimal(20,2),Slop_Value) + " & Plus
        sql &= " WHERE Slop_Code = @Slop_Code "
        sql &= " AND CONVERT(VARCHAR(10), Convert(DateTime,Slop_Date) , 112) Between " & _D & " AND 99999999 "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Slop_Code", SqlDbType.NVarChar, 10).Value = Slop_Code
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Insert_Marker_Report(ByVal Date_Marker As String, ByVal Marker_Code As String, ByVal Recieve As String, ByVal Loss As String, ByVal Plus As String, ByVal _282 As String, ByVal _28 As String, ByVal _36 As String, ByVal shore As String, ByVal User_Create As String, ByVal Date_Time As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Marker_Report_Point(Date_Marker,Marker_Code,Recieve,Loss,Plus,_282,_28,_36,shore,User_Create,Date_Time) "
        sql &= " VALUES(@Date_Marker,@Marker_Code,@Recieve,@Loss,@Plus,@_282,@_28,@_36,@shore,@User_Create,@Date_Time) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Date_Marker", SqlDbType.NVarChar, 8).Value = Date_Marker
        cmd.Parameters.Add("@Marker_Code", SqlDbType.NVarChar, 10).Value = Marker_Code
        cmd.Parameters.Add("@Recieve", SqlDbType.NVarChar, 10).Value = Recieve
        cmd.Parameters.Add("@Loss", SqlDbType.NVarChar, 10).Value = Loss
        cmd.Parameters.Add("@Plus", SqlDbType.NVarChar, 10).Value = Plus
        cmd.Parameters.Add("@_282", SqlDbType.NVarChar, 10).Value = _282
        cmd.Parameters.Add("@_28", SqlDbType.NVarChar, 10).Value = _28
        cmd.Parameters.Add("@_36", SqlDbType.NVarChar, 10).Value = _36
        cmd.Parameters.Add("@shore", SqlDbType.NVarChar, 10).Value = shore
        cmd.Parameters.Add("@User_Create", SqlDbType.NVarChar, 50).Value = User_Create
        cmd.Parameters.Add("@Date_Time", SqlDbType.NVarChar, 50).Value = Date_Time
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertSlop_Transection(ByVal Slop_Code As String, ByVal Slop_Date As String, ByVal Slop_Value As String, ByVal Slop_Action As String, ByVal Slop_By As String, ByVal Slop_Time As String, ByVal slop_remark As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Slop_Transection(Slop_Code,Slop_Date,Slop_Value,Slop_Action,Slop_By,Slop_Time,Slop_Remark) "
        sql &= " VALUES(@Slop_Code,@Slop_Date,@Slop_Value,@Slop_Action,@Slop_By,@Slop_Time,@Slop_Remark) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Slop_Code", SqlDbType.NVarChar, 10).Value = Slop_Code
        cmd.Parameters.Add("@Slop_Date", SqlDbType.NVarChar, 15).Value = Slop_Date
        cmd.Parameters.Add("@Slop_Value", SqlDbType.NVarChar, 20).Value = Slop_Value
        cmd.Parameters.Add("@Slop_Action", SqlDbType.NVarChar, 1).Value = Slop_Action
        cmd.Parameters.Add("@Slop_By", SqlDbType.NVarChar, 50).Value = Slop_By
        cmd.Parameters.Add("@Slop_Time", SqlDbType.NVarChar, 50).Value = Slop_Time
        cmd.Parameters.Add("@Slop_Remark", SqlDbType.NVarChar, 500).Value = slop_remark
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLine(ByVal eventSQL As String, ByVal Line_Code As String, ByVal Line_Name As String, ByVal Shore_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Line(Line_Code,Line_Name,Shore_Code) "
            sql &= " VALUES(@Line_Code,@Line_Name,@Shore_Code)"
        Else
            sql = "UPDATE Line SET Line_Name = @Line_Name , Shore_Code = @Shore_Code "
            sql &= " WHERE Line_Code = @Line_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Line_Code", SqlDbType.NVarChar, 10).Value = Line_Code
        cmd.Parameters.Add("@Line_Name", SqlDbType.NVarChar, 500).Value = Line_Name
        cmd.Parameters.Add("@Shore_Code", SqlDbType.NVarChar, 10).Value = Shore_Code
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertGL_Account(ByVal eventSQL As String, ByVal Gl_account As String, ByVal Gl_Name As String, ByVal Bank_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Gl_Account(Gl_Account,Gl_Name,Bank_Code) "
            sql &= " VALUES(@Gl_Account,@Gl_Name,@Bank_Code)"
        Else
            sql = "UPDATE Gl_Account SET Gl_Name = @Gl_Name , Bank_Code = @Bank_Code "
            sql &= " WHERE Gl_account = @Gl_account "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Gl_Account", SqlDbType.NVarChar, 10).Value = Gl_account
        cmd.Parameters.Add("@Gl_Name", SqlDbType.NVarChar, 200).Value = Gl_Name
        cmd.Parameters.Add("@Bank_Code", SqlDbType.NVarChar, 30).Value = Bank_Code
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Insert_Holiday(ByVal eventSQL As String, ByVal Day As String, ByVal Month As String, ByVal Year As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Holiday(Day,Month,Year) "
            sql &= " VALUES(@Day,@Month,@Year)"
        Else
            sql = "UPDATE Holiday SET Day = @Day , Month = @Month , Year = @Year "
            sql &= " WHERE Day = @Day2 AND Month = @Month2 AND Year = @Year2  "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Day", SqlDbType.NVarChar, 2).Value = Day
        cmd.Parameters.Add("@Month", SqlDbType.NVarChar, 2).Value = Month
        cmd.Parameters.Add("@Year", SqlDbType.NVarChar, 4).Value = Year
        If (eventSQL <> "") Then
            cmd.Parameters.Add("@Day2", SqlDbType.NVarChar, 2).Value = CDate(eventSQL).ToString("dd")
            cmd.Parameters.Add("@Month2", SqlDbType.NVarChar, 2).Value = CDate(eventSQL).ToString("MM")
            cmd.Parameters.Add("@Year2", SqlDbType.NVarChar, 4).Value = eventSQL.Split(" ")(2)
        End If
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Update_StockActive(ByVal Stock_Code As String, ByVal Type_Additional As String, ByVal Color As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "UPDATE Stock SET Active = 'Y' "
        sql &= " WHERE Stock_Code = @Stock_Code  ; "
        sql &= "UPDATE Stock SET Active = 'N' "
        sql &= " WHERE Stock_Code <>  @Stock_Code And Type_Additional = @Type_Additional AND Color = @Color ; "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Stock_Code", SqlDbType.NVarChar, 10).Value = Stock_Code
        cmd.Parameters.Add("@Type_Additional", SqlDbType.NVarChar, 1).Value = Type_Additional
        cmd.Parameters.Add("@Color", SqlDbType.NVarChar, 10).Value = Color
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Update_StockValue(ByVal Type As String, ByVal Stock_Code As String, ByVal Amount As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (Type = "A") Then
            sql = "UPDATE Stock SET Amount = (convert(Decimal(7,3),Amount) + @Amount) "
        Else
            sql = "UPDATE Stock SET Amount = (convert(Decimal(7,3),Amount) - @Amount) "
        End If

        sql &= " WHERE Stock_Code = @Stock_Code ; "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Stock_Code", SqlDbType.NVarChar, 10).Value = Stock_Code
        cmd.Parameters.Add("@Amount", SqlDbType.NVarChar, 10).Value = Amount
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Insert_StockAdd_Remove(ByVal Stock_Code As String, ByVal Type_Event As String, ByVal Amount As String, ByVal User_Create As String, ByVal Booking_no As String, ByVal Remark As String, ByVal _Date As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Stock_Add_Remove(Stock_Code,Type_Event,Amount,User_Create,Booking_no,Remark) "
        sql &= " VALUES(@Stock_Code,@Type_Event,@Amount,@User_Create,@Booking_no,@Remark) "


        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Stock_Code", SqlDbType.NVarChar, 10).Value = Stock_Code
        cmd.Parameters.Add("@Type_Event", SqlDbType.NVarChar, 1).Value = Type_Event
        cmd.Parameters.Add("@Amount", SqlDbType.NVarChar, 10).Value = Amount
        cmd.Parameters.Add("@User_Create", SqlDbType.NVarChar, 50).Value = User_Create
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Remark", SqlDbType.NVarChar, 500).Value = Remark
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Insert_Stock(ByVal eventSQL As String, ByVal Stock_Code As String, ByVal Type_Additional As String, ByVal Color As String, ByVal Grade As String, ByVal Brand As String, ByVal Description As String, ByVal Amount As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Stock(Stock_Code,Type_Additional,Color,Grade,Brand,Description,Amount) "
            sql &= " VALUES(@Stock_Code,@Type_Additional,@Color,@Grade,@Brand,@Description,@Amount) "
        Else
            sql = "UPDATE Stock SET Type_Additional = @Type_Additional , Color = @Color "
            sql &= "  , Grade = @Grade , Brand = @Brand , Description = @Description "
            sql &= " WHERE Stock_Code = @Stock_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Stock_Code", SqlDbType.NVarChar, 10).Value = Stock_Code
        cmd.Parameters.Add("@Type_Additional", SqlDbType.NVarChar, 1).Value = Type_Additional
        cmd.Parameters.Add("@Color", SqlDbType.NVarChar, 10).Value = Color
        cmd.Parameters.Add("@Grade", SqlDbType.NVarChar, 200).Value = Grade
        cmd.Parameters.Add("@Brand", SqlDbType.NVarChar, 200).Value = Brand
        cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 500).Value = Description
        cmd.Parameters.Add("@Amount", SqlDbType.NVarChar, 10).Value = Amount
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Insert_Stock_Relation(ByVal Stock_Code As String, ByVal Group_no As String, ByVal Product_no As String, ByVal Product_name As String, ByVal Point As String, ByVal Marker_Point As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Stock_Relation(Stock_Code,Group_no,Product_no,Product_name,Color_Point,Marker_Point) "
        sql &= " VALUES(@Stock_Code,@Group_no,@Product_no,@Product_name,@Point,@Marker_Point) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Stock_Code", SqlDbType.NVarChar, 10).Value = Stock_Code
        cmd.Parameters.Add("@Group_no", SqlDbType.NVarChar, 10).Value = Group_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 200).Value = Product_name
        cmd.Parameters.Add("@Point", SqlDbType.NVarChar, 10).Value = Point
        cmd.Parameters.Add("@Marker_Point", SqlDbType.NVarChar, 10).Value = Marker_Point
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoading_Unloading(ByVal eventSQL As String, ByVal Load_code As String, ByVal Shore_Code As String, ByVal Group_Code As String, ByVal Line_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Loading_Unloading(Load_code,Shore_Code,Group_Code,Line_Code) "
            sql &= " VALUES(@Load_code,@Shore_Code,@Group_Code,@Line_Code) "
        Else
            sql = "UPDATE Loading_Unloading SET Shore_Code = @Shore_Code , Group_Code = @Group_Code "
            sql &= "  , Line_Code = @Line_Code "
            sql &= " WHERE Load_code = @Load_code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Load_code", SqlDbType.NVarChar, 10).Value = Load_code
        cmd.Parameters.Add("@Shore_Code", SqlDbType.NVarChar, 10).Value = Shore_Code
        cmd.Parameters.Add("@Group_Code", SqlDbType.NVarChar, 10).Value = Group_Code
        cmd.Parameters.Add("@Line_Code", SqlDbType.NVarChar, 10).Value = Line_Code
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoading_Facility(ByVal Load_code As String, ByVal L_D As String, ByVal BookingWharf As String, ByVal Facility_Code As String, ByVal Before As String, ByVal Rate As String, ByVal Unit As String, ByVal After As String, ByVal Remark As String, ByVal Plus_Tank As String, ByVal Plus_Parcel As String, ByVal Plus_Product As String, ByVal Plus_parcel_After As String, ByVal Plus_Product_after As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = "INSERT Loading_Facility(Load_code,L_D,BookingWharf,Facility_Code,Before,Rate,Unit,After,Remark,Plus_Tank,Plus_Parcel_Before,Plus_Product_Before,Plus_Parcel_After,Plus_Product_After) "
        sql &= " VALUES(@Load_code,@L_D,@BookingWharf,@Facility_Code,@Before,@Rate,@Unit,@After,@Remark,@Plus_Tank,@Plus_Parcel_Before,@Plus_Product_Before,@Plus_Parcel_After,@Plus_Product_After) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Load_code", SqlDbType.NVarChar, 10).Value = Load_code
        cmd.Parameters.Add("@L_D", SqlDbType.NVarChar, 1).Value = L_D
        cmd.Parameters.Add("@BookingWharf", SqlDbType.NVarChar, 5).Value = BookingWharf
        cmd.Parameters.Add("@Facility_Code", SqlDbType.NVarChar, 10).Value = Facility_Code
        cmd.Parameters.Add("@Before", SqlDbType.NVarChar, 10).Value = Before
        cmd.Parameters.Add("@Rate", SqlDbType.NVarChar, 10).Value = Rate
        cmd.Parameters.Add("@Unit", SqlDbType.NVarChar, 5).Value = Unit
        cmd.Parameters.Add("@After", SqlDbType.NVarChar, 10).Value = After
        cmd.Parameters.Add("@Remark", SqlDbType.NVarChar, 400).Value = Remark
        cmd.Parameters.Add("@Plus_Tank", SqlDbType.NVarChar, 10).Value = Plus_Tank
        cmd.Parameters.Add("@Plus_Parcel_Before", SqlDbType.NVarChar, 5).Value = Plus_Parcel
        cmd.Parameters.Add("@Plus_Product_Before", SqlDbType.NVarChar, 5).Value = Plus_Product
        cmd.Parameters.Add("@Plus_Parcel_After", SqlDbType.NVarChar, 5).Value = Plus_parcel_After
        cmd.Parameters.Add("@Plus_Product_After", SqlDbType.NVarChar, 5).Value = Plus_Product_after
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertShore(ByVal eventSQL As String, ByVal Shore_Code As String, ByVal Shore_Name As String, ByVal PORT As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Shore(Shore_Code,Shore_Name,PORT) "
            sql &= " VALUES(@Shore_Code,@Shore_Name,@PORT)"
        Else
            sql = "UPDATE Shore SET Shore_Name = @Shore_Name,PORT = @PORT "
            sql &= " WHERE Shore_Code = @Shore_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Shore_Code", SqlDbType.NVarChar, 10).Value = Shore_Code
        cmd.Parameters.Add("@Shore_Name", SqlDbType.NVarChar, 500).Value = Shore_Name
        cmd.Parameters.Add("@PORT", SqlDbType.NVarChar, 1).Value = PORT
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBank(ByVal eventSQL As String, ByVal Bank_Code As String, ByVal Bank_SAP As String, ByVal Bank_Name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Bank(Bank_Code,Bank_SAP,Bank_Name) "
            sql &= " VALUES(@Bank_Code,@Bank_SAP,@Bank_Name)"
        Else
            sql = "UPDATE Bank SET Bank_SAP = @Bank_SAP,Bank_Name = @Bank_Name "
            sql &= " WHERE Bank_Code = @Bank_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Bank_Code", SqlDbType.NVarChar, 10).Value = Bank_Code
        cmd.Parameters.Add("@Bank_SAP", SqlDbType.NVarChar, 30).Value = Bank_SAP
        cmd.Parameters.Add("@Bank_Name", SqlDbType.NVarChar, 200).Value = Bank_Name
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertColor(ByVal eventSQL As String, ByVal Color_Code As String, ByVal Color_Name As String, ByVal Create_By As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Color(Color_Code,Color_Name,Create_By) "
            sql &= " VALUES(@Color_Code,@Color_Name,@Create_By)"
        Else
            sql = "UPDATE Color SET Color_Name = @Color_Name,Create_By = @Create_By "
            sql &= " WHERE Color_Code = @Color_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Color_Code", SqlDbType.NVarChar, 10).Value = Color_Code
        cmd.Parameters.Add("@Color_Name", SqlDbType.NVarChar, 200).Value = Color_Name
        cmd.Parameters.Add("@Create_By", SqlDbType.NVarChar, 50).Value = Create_By
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertTug(ByVal eventSQL As String, ByVal Tug_Code As String, ByVal Tug_Name As String, ByVal Tug_Type As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Tug(Tug_Code,Tug_Name,Tug_Type) "
            sql &= " VALUES(@Tug_Code,@Tug_Name,@Tug_Type)"
        Else
            sql = "UPDATE Tug SET Tug_Name = @Tug_Name,Tug_Type = @Tug_Type "
            sql &= " WHERE Tug_Code = @Tug_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Tug_Code", SqlDbType.NVarChar, 10).Value = Tug_Code
        cmd.Parameters.Add("@Tug_Name", SqlDbType.NVarChar, 200).Value = Tug_Name
        cmd.Parameters.Add("@Tug_Type", SqlDbType.NVarChar, 1).Value = Tug_Type
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_Bas_Vessel(ByVal eventSQL As String, ByVal BV_no As String, ByVal Company As String, ByVal Product_name As String, ByVal Wharf As String, ByVal Fender As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Booking_Bas_Vessel(BV_no,Company,Product_name,Wharf,Fender,Complete) "
            sql &= " VALUES(@BV_no,@Company,@Product_name,@Wharf,@Fender,@Complete)"
        Else
            sql = "UPDATE Booking_Bas_Vessel SET Company = @Company , Product_name = @Product_name , Wharf = @Wharf , Fender = @Fender "
            sql &= " WHERE BV_no = @BV_no "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@BV_no", SqlDbType.NVarChar, 10).Value = BV_no
        cmd.Parameters.Add("@Company", SqlDbType.NVarChar, 2000).Value = Company
        cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 200).Value = Product_name
        cmd.Parameters.Add("@Wharf", SqlDbType.NVarChar, 5).Value = Wharf
        cmd.Parameters.Add("@Fender", SqlDbType.NVarChar, 50).Value = Fender
        cmd.Parameters.Add("@Complete", SqlDbType.NVarChar, 1).Value = "N"
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateBooking_Bas_Vessel(ByVal BV_no As String, ByVal Complete As String, ByVal Send_By As String, ByVal Check_By As String, ByVal Approve_By As String, ByVal Reject_By As String, ByVal Reject_Description As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "UPDATE Booking_Bas_Vessel SET Complete = @Complete "
        If (Send_By <> "") Then
            sql &= " , Send_By = @Send_By "
        ElseIf (Check_By <> "") Then
            sql &= " , Check_By = @Check_By "
        ElseIf (Approve_By <> "") Then
            sql &= " , Approve_By = @Approve_By "
        End If
        sql &= " , Reject_By = @Reject_By "
        sql &= " , Reject_Description = @Reject_Description "

        sql &= " WHERE BV_no = @BV_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@BV_no", SqlDbType.NVarChar, 10).Value = BV_no
        cmd.Parameters.Add("@Complete", SqlDbType.NVarChar, 1).Value = Complete
        cmd.Parameters.Add("@Send_By", SqlDbType.NVarChar, 100).Value = Send_By
        cmd.Parameters.Add("@Check_By", SqlDbType.NVarChar, 100).Value = Check_By
        cmd.Parameters.Add("@Approve_By", SqlDbType.NVarChar, 100).Value = Approve_By
        cmd.Parameters.Add("@Reject_By", SqlDbType.NVarChar, 100).Value = Reject_By
        cmd.Parameters.Add("@Reject_Description", SqlDbType.NVarChar, 2000).Value = Reject_Description
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateOtherService(ByVal Ots_ID As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "UPDATE OtherService_Head SET Status = @Status "
        sql &= " WHERE Ots_ID = @Ots_ID "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Ots_ID", SqlDbType.NVarChar, 10).Value = Ots_ID
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 1).Value = Status
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBas_Vessel_In(ByVal BV_no As String, ByVal BV_Index As String, ByVal Bas_no As String, ByVal StartDate As String, ByVal StartTime As String, ByVal EndDate As String, ByVal EndTime As String, ByVal Truck6 As String, ByVal Truck810 As String, ByVal Trailer As String, ByVal Trailer2 As String, ByVal Product_Amount As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Bas_Vessel_In(BV_no,BV_Index,Bas_no,StartDate,StartTime,EndDate,EndTime,Truck6,Truck810,Trailer,Trailer2,Product_Amount) "
        sql &= " VALUES(@BV_no,@BV_Index,@Bas_no,@StartDate,@StartTime,@EndDate,@EndTime,@Truck6,@Truck810,@Trailer,@Trailer2,@Product_Amount) "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@BV_no", SqlDbType.NVarChar, 10).Value = BV_no
        cmd.Parameters.Add("@BV_Index", SqlDbType.NVarChar, 3).Value = BV_Index
        cmd.Parameters.Add("@Bas_no", SqlDbType.NVarChar, 10).Value = Bas_no
        cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar, 12).Value = StartDate
        cmd.Parameters.Add("@StartTime", SqlDbType.NVarChar, 5).Value = StartTime
        cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar, 12).Value = EndDate
        cmd.Parameters.Add("@EndTime", SqlDbType.NVarChar, 5).Value = EndTime
        cmd.Parameters.Add("@Truck6", SqlDbType.NVarChar, 10).Value = Truck6
        cmd.Parameters.Add("@Truck810", SqlDbType.NVarChar, 10).Value = Truck810
        cmd.Parameters.Add("@Trailer", SqlDbType.NVarChar, 10).Value = Trailer
        cmd.Parameters.Add("@Trailer2", SqlDbType.NVarChar, 10).Value = Trailer2
        cmd.Parameters.Add("@Product_Amount", SqlDbType.NVarChar, 20).Value = Product_Amount
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBas(ByVal eventSQL As String, ByVal Bas_no As String, ByVal Bas_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Bas_Master(Bas_no,Bas_name) "
            sql &= " VALUES(@Bas_no,@Bas_name)"
        Else
            sql = "UPDATE Bas_Master SET Bas_Name = @Bas_Name "
            sql &= " WHERE Bas_no = @Bas_no "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Bas_no", SqlDbType.NVarChar, 10).Value = Bas_no
        cmd.Parameters.Add("@Bas_Name", SqlDbType.NVarChar, 200).Value = Bas_name
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertCause_OF_DELAY(ByVal eventSQL As String, ByVal Cause_Code As String, ByVal Cause_Delay As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT CauseOfDelay(Cause_Code,Cause_Delay) "
            sql &= " VALUES(@Cause_Code,@Cause_Delay)"
        Else
            sql = "UPDATE CauseOfDelay SET Cause_Delay = @Cause_Delay "
            sql &= " WHERE Cause_Code = @Cause_Code "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Cause_Code", SqlDbType.NVarChar, 10).Value = Cause_Code
        cmd.Parameters.Add("@Cause_Delay", SqlDbType.NVarChar, 500).Value = Cause_Delay
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBuyer_Seller(ByVal eventSQL As String, ByVal BS_no As String, ByVal BS_name As String, ByVal BS_Group As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (eventSQL = "") Then
            sql = "INSERT Buyer_Seller(BS_no,BS_name,BS_Group) "
            sql &= " VALUES(@BS_no,@BS_name,@BS_Group)"
        Else
            sql = "UPDATE Buyer_Seller SET BS_name = @BS_name ,BS_Group = @BS_Group "
            sql &= " WHERE BS_no = @BS_no "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@BS_no", SqlDbType.NVarChar, 10).Value = BS_no
        cmd.Parameters.Add("@BS_name", SqlDbType.NVarChar, 200).Value = BS_name
        cmd.Parameters.Add("@BS_Group", SqlDbType.NVarChar, 1).Value = BS_Group
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function Delete_Marker_Report(ByVal Marker_Code As String, ByVal Date_Marker As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Marker_Report_Point WHERE Date_Marker = @Date_Marker And Marker_Code = @Marker_Code "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Date_Marker", SqlDbType.NVarChar, 8).Value = Date_Marker
        cmd.Parameters.Add("@Marker_Code", SqlDbType.NVarChar, 10).Value = Marker_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteSlop_Transection(ByVal Slop_Code As String, ByVal _D As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Slop_Transection WHERE Slop_Code = @Slop_Code And Slop_Date = @Slop_Date "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Slop_Code", SqlDbType.NVarChar, 10).Value = Slop_Code
        cmd.Parameters.Add("@Slop_Date", SqlDbType.NVarChar, 15).Value = _D

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteMenu(ByVal Menu_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Menu WHERE Menu_no = @Menu_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Menu_no", SqlDbType.NVarChar, 10).Value = Menu_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBas_Vessel_In(ByVal BV_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Bas_Vessel_In WHERE BV_no = @BV_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@BV_no", SqlDbType.NVarChar, 10).Value = BV_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertMENU_Role(ByVal Menu_no As String, ByVal Role_no As String, ByVal Show As String, ByVal Edit As String, ByVal Add As String, ByVal Delete As String, ByVal Approve As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Role_Menu(Menu_no,Role_no,Show_Menu,Edit_Menu,Add_Menu,Delete_Menu,Approve_Menu) "
        sql &= " VALUES(@Menu_no,@Role_no,@Show_Menu,@Edit_Menu,@Add_Menu,@Delete_Menu,@Approve_Menu)"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Menu_no", SqlDbType.NVarChar, 10).Value = Menu_no
        cmd.Parameters.Add("@Role_no", SqlDbType.NVarChar, 10).Value = Role_no
        cmd.Parameters.Add("@Show_Menu", SqlDbType.NVarChar, 1).Value = Show
        cmd.Parameters.Add("@Edit_Menu", SqlDbType.NVarChar, 1).Value = Edit
        cmd.Parameters.Add("@Add_Menu", SqlDbType.NVarChar, 1).Value = Add
        cmd.Parameters.Add("@Delete_Menu", SqlDbType.NVarChar, 1).Value = Delete
        cmd.Parameters.Add("@Approve_Menu", SqlDbType.NVarChar, 1).Value = Approve
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteMENU_Role_name(ByVal Menu_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "Delete From Role_Menu WHERE Menu_no = @Menu_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Menu_no", SqlDbType.NVarChar, 10).Value = Menu_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteMENU_Role(ByVal Role_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "Delete From Role_Menu WHERE Role_no = @Role_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Role_no", SqlDbType.NVarChar, 10).Value = Role_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertConfig(ByVal Vat As String, ByVal VeHicle_Date As String, ByVal Head_Report_ComputeDraft As String, ByVal Foot_Report_ComputeDraft As String, ByVal Head_Report_Compute As String, ByVal Foot_Report_Compute As String, ByVal Logon_Text As String, ByVal Before As String, ByVal After As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM CONFIG ; "
        sql &= "INSERT CONFIG(Vat,Vehicle_Date,Head_Report_ComputeDraft,Foot_Report_ComputeDraft,Head_Report_Compute,Foot_Report_Compute,Logon_Text,Before,After) "
        sql &= " VALUES(@Vat,@Vehicle_Date,@Head_Report_ComputeDraft,@Foot_Report_ComputeDraft,@Head_Report_Compute,@Foot_Report_Compute,@Logon_Text,@Before,@After)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Vat", SqlDbType.NVarChar, 5).Value = Vat
        cmd.Parameters.Add("@Vehicle_Date", SqlDbType.NVarChar, 8).Value = VeHicle_Date
        cmd.Parameters.Add("@Head_Report_ComputeDraft", SqlDbType.Text).Value = Head_Report_ComputeDraft
        cmd.Parameters.Add("@Foot_Report_ComputeDraft", SqlDbType.Text).Value = Foot_Report_ComputeDraft
        cmd.Parameters.Add("@Head_Report_Compute", SqlDbType.Text).Value = Head_Report_Compute
        cmd.Parameters.Add("@Foot_Report_Compute", SqlDbType.Text).Value = Foot_Report_Compute
        cmd.Parameters.Add("@Logon_Text", SqlDbType.Text).Value = Logon_Text
        cmd.Parameters.Add("@Before", SqlDbType.NVarChar, 10).Value = Before
        cmd.Parameters.Add("@After", SqlDbType.NVarChar, 10).Value = After

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateMeterial(ByVal MATERIAL As String, ByVal BASE_UOM As String, ByVal DELYG_PLNT As String, ByVal MATL_DESC As String, ByVal TEXT_LINE As String, ByVal TAXCLASS As String, ByVal Division As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Meterial SET" & vbCrLf
        sql &= " BASE_UOM = @BASE_UOM , DELYG_PLNT= @DELYG_PLNT,MATL_DESC=@MATL_DESC,TEXT_LINE=@TEXT_LINE" & vbCrLf
        sql &= ",TAXCLASS=@TAXCLASS" & vbCrLf
        sql &= ", Division=@Division" & vbCrLf
        sql &= " WHERE MATERIAL = @MATERIAL"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@BASE_UOM", SqlDbType.NVarChar, 3).Value = BASE_UOM
        cmd.Parameters.Add("@DELYG_PLNT", SqlDbType.NVarChar, 4).Value = DELYG_PLNT
        cmd.Parameters.Add("@MATL_DESC", SqlDbType.NVarChar, 40).Value = MATL_DESC
        cmd.Parameters.Add("@TEXT_LINE", SqlDbType.NVarChar, 40).Value = TEXT_LINE
        cmd.Parameters.Add("@TAXCLASS", SqlDbType.NVarChar, 1).Value = TAXCLASS
        cmd.Parameters.Add("@Division", SqlDbType.NVarChar, 2).Value = Division

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertMeterial(ByVal MATERIAL As String, ByVal BASE_UOM As String, ByVal DELYG_PLNT As String, ByVal MATL_DESC As String, ByVal TEXT_LINE As String, ByVal TAXCLASS As String, ByVal MAT_Default As String, ByVal MAT_FOR As String, ByVal MAT_Compute As String, ByVal Division As String, ByVal MAT_ComputeProduct As String, ByVal MAT_ComputebuyerSeller As String, ByVal MAT_ComputeNational As String, ByVal MAT_ComputeDestinaation As String, ByVal MAT_WHT As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Meterial(MATERIAL,BASE_UOM,DELYG_PLNT,MATL_DESC,TEXT_LINE,TAXCLASS,MAT_Default,MAT_FOR,MAT_Compute,Division,MAT_ComputeProduct,MAT_ComputebuyerSeller,MAT_ComputeNational,MAT_ComputeDestinaation,MAT_WHT) "
        sql &= " VALUES(@MATERIAL,@BASE_UOM,@DELYG_PLNT,@MATL_DESC,@TEXT_LINE,@TAXCLASS,@MAT_Default,@MAT_FOR,@MAT_Compute,@Division,@MAT_ComputeProduct,@MAT_ComputebuyerSeller,@MAT_ComputeNational,@MAT_ComputeDestinaation,@MAT_WHT)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@BASE_UOM", SqlDbType.NVarChar, 3).Value = BASE_UOM
        cmd.Parameters.Add("@DELYG_PLNT", SqlDbType.NVarChar, 4).Value = DELYG_PLNT
        cmd.Parameters.Add("@MATL_DESC", SqlDbType.NVarChar, 40).Value = MATL_DESC
        cmd.Parameters.Add("@TEXT_LINE", SqlDbType.NVarChar, 40).Value = TEXT_LINE
        cmd.Parameters.Add("@TAXCLASS", SqlDbType.NVarChar, 1).Value = TAXCLASS
        cmd.Parameters.Add("@MAT_Default", SqlDbType.NVarChar, 1).Value = MAT_Default
        cmd.Parameters.Add("@MAT_FOR", SqlDbType.NVarChar, 1).Value = MAT_FOR
        cmd.Parameters.Add("@MAT_Compute", SqlDbType.NVarChar, 1).Value = MAT_Compute
        cmd.Parameters.Add("@Division", SqlDbType.NVarChar, 2).Value = Division
        cmd.Parameters.Add("@MAT_ComputeProduct", SqlDbType.NVarChar, 1).Value = MAT_ComputeProduct
        cmd.Parameters.Add("@MAT_ComputebuyerSeller", SqlDbType.NVarChar, 1).Value = MAT_ComputebuyerSeller
        cmd.Parameters.Add("@MAT_ComputeNational", SqlDbType.NVarChar, 1).Value = MAT_ComputeNational
        cmd.Parameters.Add("@MAT_ComputeDestinaation", SqlDbType.NVarChar, 1).Value = MAT_ComputeDestinaation
        cmd.Parameters.Add("@MAT_WHT", SqlDbType.NVarChar, 2).Value = MAT_WHT

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATEVehicle(ByVal VEHICLE As String, ByVal VEH_TEXT As String, ByVal OWNER As String, ByVal REG_CNTRY As String, ByVal VEH_TYPE As String, ByVal VEH_LENGTH As String, ByVal VEH_WIDTH As String, ByVal VEH_HEIGHT As String, ByVal DRAFT As String, ByVal DIM_UOM As String, ByVal VEH_UNLWGT As String, ByVal VEH_UNLWGT_C As String, ByVal VEH_MAXWGT As String, ByVal VEH_MAXWGT_C As String, ByVal WGT_UOM As String, ByVal VEH_MAXVOL As String, ByVal VEH_MAXVOL_C As String, ByVal VOL_UOM As String, ByVal STCMNR As String, ByVal VEH_NRTUS As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " UPDATE Vessel SET " & vbCrLf
        sql &= " VEH_TEXT=@VEH_TEXT,OWNER= @OWNER,REG_CNTRY=@REG_CNTRY,VEH_TYPE=@VEH_TYPE,VEH_LENGTH=@VEH_LENGTH " & vbCrLf
        sql &= " ,VEH_WIDTH= @VEH_WIDTH,VEH_HEIGHT=@VEH_HEIGHT,DRAFT=@DRAFT,DIM_UOM=@DIM_UOM,VEH_UNLWGT=@VEH_UNLWGT" & vbCrLf
        sql &= " ,VEH_UNLWGT_C=@VEH_UNLWGT_C,VEH_MAXWGT=@VEH_MAXWGT,VEH_MAXWGT_C=@VEH_MAXWGT_C,WGT_UOM=@WGT_UOM " & vbCrLf
        sql &= " ,VEH_MAXVOL=@VEH_MAXVOL,VEH_MAXVOL_C =@VEH_MAXVOL_C,VOL_UOM=@VOL_UOM,STCMNR=@STCMNR,VEH_NRTUS=@VEH_NRTUS" & vbCrLf
        sql &= " WHERE VEHICLE=@VEHICLE " & vbCrLf

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@VEHICLE", SqlDbType.NVarChar, 10).Value = VEHICLE
        cmd.Parameters.Add("@VEH_TEXT", SqlDbType.NVarChar, 40).Value = VEH_TEXT
        cmd.Parameters.Add("@OWNER", SqlDbType.NVarChar, 20).Value = OWNER
        cmd.Parameters.Add("@REG_CNTRY", SqlDbType.NVarChar, 3).Value = REG_CNTRY
        cmd.Parameters.Add("@VEH_TYPE", SqlDbType.NVarChar, 4).Value = VEH_TYPE
        cmd.Parameters.Add("@VEH_LENGTH", SqlDbType.Decimal, 13, 3).Value = VEH_LENGTH
        cmd.Parameters.Add("@VEH_WIDTH", SqlDbType.Decimal, 13, 3).Value = VEH_WIDTH
        cmd.Parameters.Add("@VEH_HEIGHT", SqlDbType.Decimal, 13, 3).Value = VEH_HEIGHT
        cmd.Parameters.Add("@DRAFT", SqlDbType.Decimal, 13, 3).Value = DRAFT
        cmd.Parameters.Add("@DIM_UOM", SqlDbType.NVarChar, 3).Value = DIM_UOM
        cmd.Parameters.Add("@VEH_UNLWGT", SqlDbType.NVarChar, 16).Value = VEH_UNLWGT
        cmd.Parameters.Add("@VEH_UNLWGT_C", SqlDbType.NVarChar, 22).Value = VEH_UNLWGT_C
        cmd.Parameters.Add("@VEH_MAXWGT", SqlDbType.NVarChar, 16).Value = VEH_MAXWGT
        cmd.Parameters.Add("@VEH_MAXWGT_C", SqlDbType.NVarChar, 22).Value = VEH_MAXWGT_C
        cmd.Parameters.Add("@WGT_UOM", SqlDbType.NVarChar, 3).Value = WGT_UOM
        cmd.Parameters.Add("@VEH_MAXVOL", SqlDbType.NVarChar, 16).Value = VEH_MAXVOL
        cmd.Parameters.Add("@VEH_MAXVOL_C", SqlDbType.NVarChar, 22).Value = VEH_MAXVOL_C
        cmd.Parameters.Add("@VOL_UOM", SqlDbType.NVarChar, 3).Value = VOL_UOM
        cmd.Parameters.Add("@STCMNR", SqlDbType.NVarChar, 30).Value = STCMNR
        cmd.Parameters.Add("@VEH_NRTUS", SqlDbType.NVarChar, 2).Value = VEH_NRTUS

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertVehicle(ByVal VEHICLE As String, ByVal VEH_TEXT As String, ByVal OWNER As String, ByVal REG_CNTRY As String, ByVal VEH_TYPE As String, ByVal VEH_LENGTH As String, ByVal VEH_WIDTH As String, ByVal VEH_HEIGHT As String, ByVal DRAFT As String, ByVal DIM_UOM As String, ByVal VEH_UNLWGT As String, ByVal VEH_UNLWGT_C As String, ByVal VEH_MAXWGT As String, ByVal VEH_MAXWGT_C As String, ByVal WGT_UOM As String, ByVal VEH_MAXVOL As String, ByVal VEH_MAXVOL_C As String, ByVal VOL_UOM As String, ByVal STCMNR As String, ByVal VEH_NRTUS As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Vessel(VEHICLE,VEH_TEXT,OWNER,REG_CNTRY,VEH_TYPE,VEH_LENGTH,VEH_WIDTH,VEH_HEIGHT,DRAFT,DIM_UOM,VEH_UNLWGT,VEH_UNLWGT_C,VEH_MAXWGT,VEH_MAXWGT_C,WGT_UOM,VEH_MAXVOL,VEH_MAXVOL_C,VOL_UOM,STCMNR,VEH_NRTUS) "
        sql &= " VALUES(@VEHICLE,@VEH_TEXT,@OWNER,@REG_CNTRY,@VEH_TYPE,@VEH_LENGTH,@VEH_WIDTH,@VEH_HEIGHT,@DRAFT,@DIM_UOM,@VEH_UNLWGT,@VEH_UNLWGT_C,@VEH_MAXWGT,@VEH_MAXWGT_C,@WGT_UOM,@VEH_MAXVOL,@VEH_MAXVOL_C,@VOL_UOM,@STCMNR,@VEH_NRTUS) "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@VEHICLE", SqlDbType.NVarChar, 10).Value = VEHICLE
        cmd.Parameters.Add("@VEH_TEXT", SqlDbType.NVarChar, 40).Value = VEH_TEXT
        cmd.Parameters.Add("@OWNER", SqlDbType.NVarChar, 20).Value = OWNER
        cmd.Parameters.Add("@REG_CNTRY", SqlDbType.NVarChar, 3).Value = REG_CNTRY
        cmd.Parameters.Add("@VEH_TYPE", SqlDbType.NVarChar, 4).Value = VEH_TYPE
        cmd.Parameters.Add("@VEH_LENGTH", SqlDbType.Decimal, 13, 3).Value = VEH_LENGTH
        cmd.Parameters.Add("@VEH_WIDTH", SqlDbType.Decimal, 13, 3).Value = VEH_WIDTH
        cmd.Parameters.Add("@VEH_HEIGHT", SqlDbType.Decimal, 13, 3).Value = VEH_HEIGHT
        cmd.Parameters.Add("@DRAFT", SqlDbType.Decimal, 13, 3).Value = DRAFT
        cmd.Parameters.Add("@DIM_UOM", SqlDbType.NVarChar, 3).Value = DIM_UOM
        cmd.Parameters.Add("@VEH_UNLWGT", SqlDbType.NVarChar, 16).Value = VEH_UNLWGT
        cmd.Parameters.Add("@VEH_UNLWGT_C", SqlDbType.NVarChar, 22).Value = VEH_UNLWGT_C
        cmd.Parameters.Add("@VEH_MAXWGT", SqlDbType.NVarChar, 16).Value = VEH_MAXWGT
        cmd.Parameters.Add("@VEH_MAXWGT_C", SqlDbType.NVarChar, 22).Value = VEH_MAXWGT_C
        cmd.Parameters.Add("@WGT_UOM", SqlDbType.NVarChar, 3).Value = WGT_UOM
        cmd.Parameters.Add("@VEH_MAXVOL", SqlDbType.NVarChar, 16).Value = VEH_MAXVOL
        cmd.Parameters.Add("@VEH_MAXVOL_C", SqlDbType.NVarChar, 22).Value = VEH_MAXVOL_C
        cmd.Parameters.Add("@VOL_UOM", SqlDbType.NVarChar, 3).Value = VOL_UOM
        cmd.Parameters.Add("@STCMNR", SqlDbType.NVarChar, 30).Value = STCMNR
        cmd.Parameters.Add("@VEH_NRTUS", SqlDbType.NVarChar, 2).Value = VEH_NRTUS

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATEVehicle_infor(ByVal VEHICLE As String, ByVal TU_TYPE As String, ByVal TU_CLASS As String, ByVal TU_MODE As String, ByVal TU_LENGTH As String, ByVal TU_WIDTH As String, ByVal TU_HEIGHT As String, ByVal DIM_UOM As String, ByVal TU_UNLWGT As String, ByVal TU_UNLWGT_C As String, ByVal TU_MAXWGT As String, ByVal TU_MAXWGT_C As String, ByVal WGT_UOM As String, ByVal TU_MAXVOL As String, ByVal TU_MAXVOL_C As String, ByVal VOL_UOM As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " UPDATE Vehicle_Transport_Unit SET " & vbCrLf
        sql &= " TU_TYPE=@TU_TYPE,TU_CLASS=@TU_CLASS,TU_MODE=@TU_MODE,TU_LENGTH=@TU_LENGTH,TU_WIDTH=@TU_WIDTH,TU_HEIGHT=@TU_HEIGHT " & vbCrLf
        sql &= " ,DIM_UOM=@DIM_UOM,TU_UNLWGT=@TU_UNLWGT,TU_UNLWGT_C=@TU_UNLWGT_C ,TU_MAXWGT=@TU_MAXWGT,TU_MAXWGT_C=@TU_MAXWGT_C" & vbCrLf
        sql &= " ,WGT_UOM=@WGT_UOM,TU_MAXVOL=@TU_MAXVOL,TU_MAXVOL_C=@TU_MAXVOL_C,VOL_UOM=@VOL_UOM " & vbCrLf
        sql &= " WHERE VEHICLE=@VEHICLE " & vbCrLf

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@VEHICLE", SqlDbType.NVarChar, 10).Value = VEHICLE
        cmd.Parameters.Add("@TU_TYPE", SqlDbType.NVarChar, 4).Value = TU_TYPE
        cmd.Parameters.Add("@TU_CLASS", SqlDbType.NVarChar, 1).Value = TU_CLASS
        cmd.Parameters.Add("@TU_MODE", SqlDbType.NVarChar, 1).Value = TU_MODE
        cmd.Parameters.Add("@TU_LENGTH", SqlDbType.Decimal, 13, 3).Value = TU_LENGTH
        cmd.Parameters.Add("@TU_WIDTH", SqlDbType.Decimal, 13, 3).Value = TU_WIDTH
        cmd.Parameters.Add("@TU_HEIGHT", SqlDbType.Decimal, 13, 3).Value = TU_HEIGHT
        cmd.Parameters.Add("@DIM_UOM", SqlDbType.NVarChar, 3).Value = DIM_UOM
        cmd.Parameters.Add("@TU_UNLWGT", SqlDbType.NVarChar, 16).Value = TU_UNLWGT
        cmd.Parameters.Add("@TU_UNLWGT_C", SqlDbType.NVarChar, 22).Value = TU_UNLWGT_C
        cmd.Parameters.Add("@TU_MAXWGT", SqlDbType.NVarChar, 16).Value = TU_MAXWGT
        cmd.Parameters.Add("@TU_MAXWGT_C", SqlDbType.NVarChar, 22).Value = TU_MAXWGT_C
        cmd.Parameters.Add("@WGT_UOM", SqlDbType.NVarChar, 3).Value = WGT_UOM
        cmd.Parameters.Add("@TU_MAXVOL", SqlDbType.NVarChar, 16).Value = TU_MAXVOL
        cmd.Parameters.Add("@TU_MAXVOL_C", SqlDbType.NVarChar, 22).Value = TU_MAXVOL_C
        cmd.Parameters.Add("@VOL_UOM", SqlDbType.NVarChar, 3).Value = VOL_UOM

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertVehicle_infor(ByVal VEHICLE As String, ByVal TU_TYPE As String, ByVal TU_CLASS As String, ByVal TU_MODE As String, ByVal TU_LENGTH As String, ByVal TU_WIDTH As String, ByVal TU_HEIGHT As String, ByVal DIM_UOM As String, ByVal TU_UNLWGT As String, ByVal TU_UNLWGT_C As String, ByVal TU_MAXWGT As String, ByVal TU_MAXWGT_C As String, ByVal WGT_UOM As String, ByVal TU_MAXVOL As String, ByVal TU_MAXVOL_C As String, ByVal VOL_UOM As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Vehicle_Transport_Unit(VEHICLE,TU_TYPE,TU_CLASS,TU_MODE,TU_LENGTH,TU_WIDTH,TU_HEIGHT,DIM_UOM,TU_UNLWGT,TU_UNLWGT_C,TU_MAXWGT,TU_MAXWGT_C,WGT_UOM,TU_MAXVOL,TU_MAXVOL_C,VOL_UOM) "
        sql &= " VALUES(@VEHICLE,@TU_TYPE,@TU_CLASS,@TU_MODE,@TU_LENGTH,@TU_WIDTH,@TU_HEIGHT,@DIM_UOM,@TU_UNLWGT,@TU_UNLWGT_C,@TU_MAXWGT,@TU_MAXWGT_C,@WGT_UOM,@TU_MAXVOL,@TU_MAXVOL_C,@VOL_UOM) "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@VEHICLE", SqlDbType.NVarChar, 10).Value = VEHICLE
        cmd.Parameters.Add("@TU_TYPE", SqlDbType.NVarChar, 4).Value = TU_TYPE
        cmd.Parameters.Add("@TU_CLASS", SqlDbType.NVarChar, 1).Value = TU_CLASS
        cmd.Parameters.Add("@TU_MODE", SqlDbType.NVarChar, 1).Value = TU_MODE
        cmd.Parameters.Add("@TU_LENGTH", SqlDbType.Decimal, 13, 3).Value = TU_LENGTH
        cmd.Parameters.Add("@TU_WIDTH", SqlDbType.Decimal, 13, 3).Value = TU_WIDTH
        cmd.Parameters.Add("@TU_HEIGHT", SqlDbType.Decimal, 13, 3).Value = TU_HEIGHT
        cmd.Parameters.Add("@DIM_UOM", SqlDbType.NVarChar, 3).Value = DIM_UOM
        cmd.Parameters.Add("@TU_UNLWGT", SqlDbType.NVarChar, 16).Value = TU_UNLWGT
        cmd.Parameters.Add("@TU_UNLWGT_C", SqlDbType.NVarChar, 22).Value = TU_UNLWGT_C
        cmd.Parameters.Add("@TU_MAXWGT", SqlDbType.NVarChar, 16).Value = TU_MAXWGT
        cmd.Parameters.Add("@TU_MAXWGT_C", SqlDbType.NVarChar, 22).Value = TU_MAXWGT_C
        cmd.Parameters.Add("@WGT_UOM", SqlDbType.NVarChar, 3).Value = WGT_UOM
        cmd.Parameters.Add("@TU_MAXVOL", SqlDbType.NVarChar, 16).Value = TU_MAXVOL
        cmd.Parameters.Add("@TU_MAXVOL_C", SqlDbType.NVarChar, 22).Value = TU_MAXVOL_C
        cmd.Parameters.Add("@VOL_UOM", SqlDbType.NVarChar, 3).Value = VOL_UOM

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function
    Public Function UpdateSubMeterial(ByVal MATERIAL As String, ByVal TABNAME As String, ByVal VKORG As String, ByVal VTWEG As String, ByVal WERKS As String, ByVal KUNNR As String, ByVal DATAB As String, ByVal DATBI As String, ByVal KBETR As String, ByVal KONWA As String, ByVal KPEIN As String, ByVal KMEIN As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " UPDATE SubMeterial SET " & vbCrLf
        sql &= " TABNAME=@TABNAME,VKORG = @VKORG,VTWEG=@VTWEG" & vbCrLf
        sql &= " ,WERKS=@WERKS,KUNNR=@KUNNR,DATAB=@DATAB" & vbCrLf
        sql &= " ,DATBI=@DATBI,KBETR=@KBETR,KONWA=@KONWA,KPEIN=@KPEIN,KMEIN=@KMEIN " & vbCrLf
        sql &= " WHERE MATERIAL = @MATERIAL AND WERKS=@WERKS " & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@TABNAME", SqlDbType.NVarChar, 4).Value = TABNAME
        cmd.Parameters.Add("@VKORG", SqlDbType.NVarChar, 4).Value = VKORG
        cmd.Parameters.Add("@VTWEG", SqlDbType.NVarChar, 4).Value = VTWEG
        cmd.Parameters.Add("@WERKS", SqlDbType.NVarChar, 4).Value = WERKS
        cmd.Parameters.Add("@KUNNR", SqlDbType.NVarChar, 10).Value = KUNNR
        cmd.Parameters.Add("@DATAB", SqlDbType.NVarChar, 8).Value = DATAB
        cmd.Parameters.Add("@DATBI", SqlDbType.NVarChar, 8).Value = DATBI
        cmd.Parameters.Add("@KBETR", SqlDbType.Decimal, 11, 2).Value = KBETR
        cmd.Parameters.Add("@KONWA", SqlDbType.NVarChar, 5).Value = KONWA
        cmd.Parameters.Add("@KPEIN", SqlDbType.NVarChar, 5).Value = KPEIN
        cmd.Parameters.Add("@KMEIN", SqlDbType.NVarChar, 3).Value = KMEIN

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateSubMeterialUnit(ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0

        sql = " Update SubMeterial " & vbCrLf
        sql &= " Set Unit = '' " & vbCrLf
        sql &= " WHERE Unit is Null " & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertSubMeterial(ByVal MATERIAL As String, ByVal TABNAME As String, ByVal VKORG As String, ByVal VTWEG As String, ByVal WERKS As String, ByVal KUNNR As String, ByVal DATAB As String, ByVal DATBI As String, ByVal KBETR As String, ByVal KONWA As String, ByVal KPEIN As String, ByVal KMEIN As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT SubMeterial(MATERIAL,TABNAME,VKORG,VTWEG,WERKS,KUNNR,DATAB,DATBI,KBETR,KONWA,KPEIN,KMEIN) "
        sql &= " VALUES(@MATERIAL,@TABNAME,@VKORG,@VTWEG,@WERKS,@KUNNR,@DATAB,@DATBI,@KBETR,@KONWA,@KPEIN,@KMEIN)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@TABNAME", SqlDbType.NVarChar, 4).Value = TABNAME
        cmd.Parameters.Add("@VKORG", SqlDbType.NVarChar, 4).Value = VKORG
        cmd.Parameters.Add("@VTWEG", SqlDbType.NVarChar, 4).Value = VTWEG
        cmd.Parameters.Add("@WERKS", SqlDbType.NVarChar, 4).Value = WERKS
        cmd.Parameters.Add("@KUNNR", SqlDbType.NVarChar, 10).Value = KUNNR
        cmd.Parameters.Add("@DATAB", SqlDbType.NVarChar, 8).Value = DATAB
        cmd.Parameters.Add("@DATBI", SqlDbType.NVarChar, 8).Value = DATBI
        cmd.Parameters.Add("@KBETR", SqlDbType.Decimal, 11, 2).Value = KBETR
        cmd.Parameters.Add("@KONWA", SqlDbType.NVarChar, 5).Value = KONWA
        cmd.Parameters.Add("@KPEIN", SqlDbType.NVarChar, 5).Value = KPEIN
        cmd.Parameters.Add("@KMEIN", SqlDbType.NVarChar, 3).Value = KMEIN

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertMaterial_Product(ByVal Material As String, ByVal Product_no As String, ByVal Product_name As String, ByVal Product_Load As String, ByVal Product_Disch As String, ByVal Type As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT Material_Product(Material,Product_no,Product_name,Product_Load,Product_Disch,Type) "
        sql &= " VALUES(@Material,@Product_no,@Product_name,@Product_Load,@Product_Disch,@Type)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = Material
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Product_name", SqlDbType.NVarChar, 200).Value = Product_name
        cmd.Parameters.Add("@Product_Load", SqlDbType.NVarChar, 1).Value = Product_Load
        cmd.Parameters.Add("@Product_Disch", SqlDbType.NVarChar, 1).Value = Product_Disch
        cmd.Parameters.Add("@Type", SqlDbType.NVarChar, 1).Value = Type

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateVehicle_Date(ByVal Vehicle_Date As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "UPDATE Config SET "
        sql &= " Vehicle_Date = @Vehicle_Date "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Vehicle_Date", SqlDbType.NVarChar, 8).Value = Vehicle_Date

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteMaterial_Product(ByVal Material As String, ByVal Type As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Material_Product WHERE Material = @Material AND Type = @Type "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material
        cmd.Parameters.Add("@Type", SqlDbType.NVarChar, 1).Value = Type
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function
#Region "User"
    Public Function DeleteUser(ByVal user_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM User_Role WHERE User_name = @User_name "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@User_name", SqlDbType.NVarChar, 50).Value = user_name

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteUserIPORT(ByVal user_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM UserIPORT WHERE User_name = @User_name "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@User_name", SqlDbType.NVarChar, 50).Value = user_name

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeletePRODUCT(ByVal Product As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Product WHERE Product_no = @product "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Product", SqlDbType.NVarChar, 50).Value = Product

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteFacility(ByVal Facility_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Facility WHERE Facility_Code = @Facility_Code "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Facility_Code", SqlDbType.NVarChar, 10).Value = Facility_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteShore(ByVal Shore_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Shore WHERE Shore_Code = @Shore_Code "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Shore_Code", SqlDbType.NVarChar, 10).Value = Shore_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteSlop(ByVal Slop As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Slop_Master WHERE Slop_Code = @Slop "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Slop", SqlDbType.NVarChar, 10).Value = Slop

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteLine(ByVal Line_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Line WHERE Line_Code = @Line_Code "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Line_Code", SqlDbType.NVarChar, 10).Value = Line_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteGL(ByVal Gl_Account As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Gl_Account WHERE Gl_Account = @Gl_Account "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Gl_Account", SqlDbType.NVarChar, 10).Value = Gl_Account

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteHoliday(ByVal Day As String, ByVal Month As String, ByVal Year As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Holiday WHERE Day = @Day And Month = @Month AND Year = @Year "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Day", SqlDbType.NVarChar, 2).Value = Day
        cmd.Parameters.Add("@Month", SqlDbType.NVarChar, 2).Value = Month
        cmd.Parameters.Add("@Year", SqlDbType.NVarChar, 4).Value = Year

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBank(ByVal Bank_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Bank WHERE Bank_Code = @Bank_Code; "
        sql &= " DELETE FROM Gl_Account WHERE Bank_Code = @Bank_Code; "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Bank_Code", SqlDbType.NVarChar, 10).Value = Bank_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteColor(ByVal Color As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Color WHERE Color_Code = @Color; "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Color", SqlDbType.NVarChar, 10).Value = Color

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBookingWharf(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM BookingWharf WHERE Booking_no = @Booking_no; "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteStock(ByVal Stock_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Stock WHERE Stock_Code = @Stock_Code; "
        sql &= " DELETE FROM Stock_Relation WHERE Stock_Code =  @Stock_Code;"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Stock_Code", SqlDbType.NVarChar, 10).Value = Stock_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteTug(ByVal Tug_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Tug WHERE Tug_Code = @Tug_Code; "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Tug_Code", SqlDbType.NVarChar, 10).Value = Tug_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBooking_Bas_Vessel(ByVal BV_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Booking_Bas_Vessel WHERE BV_no = @BV_no; "
        sql &= " DELETE FROM Bas_Vessel_In  WHERE BV_no = @BV_no; "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@BV_no", SqlDbType.NVarChar, 10).Value = BV_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBas(ByVal Bas_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Bas_Master WHERE Bas_no = @Bas; "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Bas", SqlDbType.NVarChar, 10).Value = Bas_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteCauseOFdelay(ByVal Cause As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM CauseOfDelay WHERE Cause_Code = @Cause_Code; "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Cause_Code", SqlDbType.NVarChar, 10).Value = Cause

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteStock_Relation(ByVal Stock_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Stock_Relation WHERE Stock_Code = @Stock_Code "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Stock_Code", SqlDbType.NVarChar, 10).Value = Stock_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteLoading_Facility(ByVal Loading_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Loading_Facility WHERE Load_Code = @Loading_Code "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Loading_Code", SqlDbType.NVarChar, 10).Value = Loading_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function


    Public Function DeleteLoading_Unloading(ByVal Loading_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Loading_Unloading WHERE Load_Code = @Loading_Code ;"
        sql &= " DELETE FROM Loading_Facility WHERE Load_Code = @Loading_Code ; "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Loading_Code", SqlDbType.NVarChar, 10).Value = Loading_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeletePRODUCTGroup(ByVal Group_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Product_Group WHERE Group_no = @Group_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Group_no", SqlDbType.NVarChar, 10).Value = Group_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBuyer_Seller(ByVal BS_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Buyer_Seller WHERE BS_no = @BS_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@BS_no", SqlDbType.NVarChar, 10).Value = BS_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertUser(ByVal EventSQL As String, ByVal User_name As String, ByVal Password As String, ByVal Name As String, ByVal Email As String, ByVal Status As String, ByVal Customer As String, ByVal Customer_name As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (EventSQL = "") Then
            sql = "INSERT UserIPORT(User_name,Password,Name,Email,Status"
            If Not (Customer = "") Then
                sql &= ",Customer_no,Customer_name"
            End If
            sql &= ") VALUES(@User_name,@Password,@Name,@Email,@Status"
            If Not (Customer = "") Then
                sql &= ",@Customer_no,@Customer_name"
            End If
            sql &= ")"
        Else
            sql = " UPDATE UserIPORT SET Password = @Password , Name = @Name  , Email = @Email , Status = @Status "
            If Not (Customer = "") Then
                sql &= ", Customer_no = @Customer_no , Customer_name = @Customer_name "
            End If
            sql &= " WHERE User_name = @User_name "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@User_name", SqlDbType.NVarChar, 50).Value = User_name
        cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 200).Value = Password
        cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 200).Value = Name
        cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 1000).Value = Email
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 1).Value = Status
        If Not (Customer = "") Then
            cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 10).Value = Customer
            cmd.Parameters.Add("@Customer_name", SqlDbType.NVarChar, 200).Value = Customer_name
        End If
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateUserPassword(ByVal User_name As String, ByVal Password As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE UserIPORT SET Password = @Password "
        sql &= " WHERE User_name = @User_name "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@User_name", SqlDbType.NVarChar, 50).Value = User_name
        cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 200).Value = Password
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertUserMASTER_P(ByVal User_name As String, ByVal Master_P As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE UserIPORT SET Master_P = @Master_P "
        sql &= " WHERE User_name = @User_name "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@User_name", SqlDbType.NVarChar, 50).Value = User_name
        cmd.Parameters.Add("@Master_P", SqlDbType.NVarChar, 1).Value = Master_P
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertUserRole(ByVal EventInsert As String, ByVal User_name As String, ByVal Role_no As String, ByVal User_Create As String, ByVal Last_Role As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If (EventInsert = "") Then
            sql = "INSERT User_Role(User_name,Role_no,User_Create) "
            sql &= " VALUES(@User_name,@Role_no,@User_Create)"
        Else
            'UPDATE
            sql = "UPDATE User_Role SET Role_no = @Role_no , User_Modify = @User_Modify  WHERE User_name = @User_name AND Role_no = @Last_Role "
        End If

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@User_name", SqlDbType.NVarChar, 50).Value = User_name
        cmd.Parameters.Add("@Role_no", SqlDbType.NVarChar, 10).Value = Role_no
        If (EventInsert = "") Then
            cmd.Parameters.Add("@User_Create", SqlDbType.NVarChar, 50).Value = User_Create
        Else
            'UPDATE
            cmd.Parameters.Add("@User_Modify", SqlDbType.NVarChar, 50).Value = User_Create
            cmd.Parameters.Add("@Last_Role", SqlDbType.NVarChar, 10).Value = Last_Role
        End If

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function
#End Region


#Region "Relation"
    Public Function UpdateMeterial(ByVal MATERIAL As String, ByVal MAT_Default As String, ByVal MAT_WHT As String, ByVal MAT_Naitonal As String, ByVal MAT_For As String, ByVal PORT As String, ByVal MAT_Relation As String, ByVal MAT_BUY As String, ByVal MAT_Product As String, ByVal MAT_Load As String, ByVal MAT_Disch As String, ByVal MAT_Compute As String, ByVal MAT_ComputeDestinaation As String, ByVal MAT_ComputeLoad As String, ByVal MAT_ComputeDisch As String, ByVal MAT_ComputeBuy As String, ByVal MAT_VesselNation As String, ByVal MAT_ComputebuyerSeller As String, ByVal MAT_ComputeNational As String, ByVal MAT_ComputeProduct As String, ByVal MAT_ComputeProduct_Load As String, ByVal MAT_ComputeProduct_Disch As String, ByVal MAT_DWToperate As String, ByVal MAT_Shifting As String, ByVal MAT_Operate As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "UPDATE Meterial "
        sql &= " SET MAT_Default = @MAT_Default"
        sql &= "    ,MAT_WHT = @MAT_WHT "
        sql &= "   ,MAT_National = @MAT_National "
        sql &= "   ,MAT_For = @MAT_For "
        sql &= "   ,MAT_PORT = @PORT "
        sql &= "   ,MAT_Relation = @MAT_Relation "
        sql &= "   ,MAT_BUY = @MAT_BUY "
        sql &= "   ,MAT_Product = @MAT_Product"
        sql &= "   ,MAT_Load = @MAT_Load "
        sql &= "   ,MAT_Disch = @MAT_Disch "
        sql &= "   ,MAT_Compute = @MAT_Compute "
        sql &= "   ,MAT_ComputeDestinaation = @MAT_ComputeDestinaation "
        sql &= "   ,MAT_ComputeLoad = @MAT_ComputeLoad "
        sql &= "   ,MAT_ComputeDisch = @MAT_ComputeDisch "
        sql &= "   ,MAT_ComputeBuy = @MAT_ComputeBuy "
        sql &= "   ,MAT_ComputebuyerSeller = @MAT_ComputebuyerSeller "
        sql &= "   ,MAT_VesselNation = @MAT_VesselNation "
        sql &= "   ,MAT_ComputeNational = @MAT_ComputeNational "
        sql &= "   ,MAT_ComputeProduct = @MAT_ComputeProduct "
        sql &= "   ,MAT_ComputeProduct_Load = @MAT_ComputeProduct_Load "
        sql &= "   ,MAT_ComputeProduct_Disch = @MAT_ComputeProduct_Disch "
        sql &= "   ,MAT_DWToperate = @MAT_DWToperate "
        sql &= "   ,MAT_Shifting = @MAT_Shifting "
        sql &= "   ,MAT_Operate = @MAT_Operate "
        sql &= " WHERE MATERIAL = @MATERIAL"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@MAT_Default", SqlDbType.NVarChar, 1).Value = MAT_Default
        cmd.Parameters.Add("@MAT_WHT", SqlDbType.NVarChar, 2).Value = MAT_WHT
        cmd.Parameters.Add("@MAT_National", SqlDbType.NVarChar, 1).Value = MAT_Naitonal
        cmd.Parameters.Add("@MAT_For", SqlDbType.NVarChar, 1).Value = MAT_For
        cmd.Parameters.Add("@PORT", SqlDbType.NVarChar, 1).Value = PORT
        cmd.Parameters.Add("@MAT_Relation", SqlDbType.NVarChar, 1).Value = MAT_Relation
        cmd.Parameters.Add("@MAT_BUY", SqlDbType.NVarChar, 1).Value = MAT_BUY
        cmd.Parameters.Add("@MAT_Product", SqlDbType.NVarChar, 1).Value = MAT_Product
        cmd.Parameters.Add("@MAT_Compute", SqlDbType.NVarChar, 1).Value = MAT_Compute
        cmd.Parameters.Add("@MAT_ComputeDestinaation", SqlDbType.NVarChar, 1).Value = MAT_ComputeDestinaation
        cmd.Parameters.Add("@MAT_ComputeLoad", SqlDbType.NVarChar, 1).Value = MAT_ComputeLoad
        cmd.Parameters.Add("@MAT_ComputeDisch", SqlDbType.NVarChar, 1).Value = MAT_ComputeDisch
        cmd.Parameters.Add("@MAT_ComputeBuy", SqlDbType.NVarChar, 1).Value = MAT_ComputeBuy
        cmd.Parameters.Add("@MAT_Load", SqlDbType.NVarChar, 1).Value = MAT_Load
        cmd.Parameters.Add("@MAT_Disch", SqlDbType.NVarChar, 1).Value = MAT_Disch
        cmd.Parameters.Add("@MAT_VesselNation", SqlDbType.NVarChar, 1).Value = MAT_VesselNation
        cmd.Parameters.Add("@MAT_ComputebuyerSeller", SqlDbType.NVarChar, 1).Value = MAT_ComputebuyerSeller
        cmd.Parameters.Add("@MAT_ComputeNational", SqlDbType.NVarChar, 1).Value = MAT_ComputeNational
        cmd.Parameters.Add("@MAT_ComputeProduct", SqlDbType.NVarChar, 1).Value = MAT_ComputeProduct
        cmd.Parameters.Add("@MAT_ComputeProduct_Load", SqlDbType.NVarChar, 1).Value = MAT_ComputeProduct_Load
        cmd.Parameters.Add("@MAT_ComputeProduct_Disch", SqlDbType.NVarChar, 1).Value = MAT_ComputeProduct_Disch
        cmd.Parameters.Add("@MAT_DWToperate", SqlDbType.NVarChar, 20).Value = MAT_DWToperate
        cmd.Parameters.Add("@MAT_Shifting", SqlDbType.NVarChar, 20).Value = MAT_Shifting
        cmd.Parameters.Add("@MAT_Operate", SqlDbType.NVarChar, 1).Value = MAT_Operate
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateSubMeterial(ByVal MATERIAL As String, ByVal UNIT As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "UPDATE subMeterial "
        sql &= " SET UNIT = @UNIT "
        sql &= " WHERE MATERIAL = @MATERIAL"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@MATERIAL", SqlDbType.NVarChar, 18).Value = MATERIAL
        cmd.Parameters.Add("@UNIT", SqlDbType.NVarChar, 10).Value = UNIT

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertRelationMATERIAL(ByVal MAT_CODE As String, ByVal Meterial As String, ByVal Mat_Name As String, ByVal Mat_Rate As String, ByVal Relation As String, ByVal Point_Start As String, ByVal Point_End As String, ByVal Money As String, ByVal Point_Unit As String, ByVal Vessel_national As String, ByVal Vessel_Destination As String, ByVal Data3 As String, ByVal Compute_Between As String, ByVal Customer_no As String, ByVal Customer_name As String, ByVal Customer_Rate As String, ByVal Customer_Money As String, ByVal Compute_Count As String, ByVal LowRate As String, ByVal LowRate_Money As String, ByVal Compute_C As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "INSERT RelationMeterial(Mat_Code,Meterial,Mat_Name,Mat_Rate,Relation,Point_Start,Point_End,Money,Point_Unit,Vessel_National,Vessel_Destination,Data3,Compute_Between,Customer_no,Customer_name,Customer_Rate,Customer_Money,Compute_Count,LowRate,LowRate_Money,Compute_C) "
        sql &= " VALUES(@Mat_Code,@Meterial,@Mat_Name,@Mat_Rate,@Relation,@Point_Start,@Point_End,@Money,@Point_Unit,@Vessel_National,@Vessel_Destination,@Data3,@Compute_Between,@Customer_no,@Customer_name,@Customer_Rate,@Customer_Money,@Compute_Count,@LowRate,@LowRate_Money,@Compute_C)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Mat_Code", SqlDbType.NVarChar, 10).Value = MAT_CODE
        cmd.Parameters.Add("@Meterial", SqlDbType.NVarChar, 18).Value = Meterial
        cmd.Parameters.Add("@Mat_Name", SqlDbType.NVarChar, 500).Value = Mat_Name
        cmd.Parameters.Add("@Mat_Rate", SqlDbType.NVarChar, 20).Value = Mat_Rate
        cmd.Parameters.Add("@Relation", SqlDbType.NVarChar, 5).Value = Relation
        cmd.Parameters.Add("@Point_Start", SqlDbType.NVarChar, 10).Value = Point_Start
        cmd.Parameters.Add("@Point_End", SqlDbType.NVarChar, 10).Value = Point_End
        cmd.Parameters.Add("@Money", SqlDbType.NVarChar, 8).Value = Money
        cmd.Parameters.Add("@Point_Unit", SqlDbType.NVarChar, 10).Value = Point_Unit
        cmd.Parameters.Add("@Vessel_National", SqlDbType.NVarChar, 1).Value = Vessel_national
        cmd.Parameters.Add("@Vessel_Destination", SqlDbType.NVarChar, 1).Value = Vessel_Destination
        cmd.Parameters.Add("@Data3", SqlDbType.NVarChar, 1).Value = Data3
        cmd.Parameters.Add("@Compute_Between", SqlDbType.NVarChar, 1).Value = Compute_Between
        cmd.Parameters.Add("@Customer_no", SqlDbType.NVarChar, 250).Value = Customer_no
        cmd.Parameters.Add("@Customer_name", SqlDbType.NVarChar, 1200).Value = Customer_name
        cmd.Parameters.Add("@Customer_Rate", SqlDbType.NVarChar, 1000).Value = Customer_Rate
        cmd.Parameters.Add("@Customer_Money", SqlDbType.NVarChar, 1000).Value = Customer_Money
        cmd.Parameters.Add("@Compute_Count", SqlDbType.NVarChar, 10).Value = Compute_Count
        cmd.Parameters.Add("@LowRate", SqlDbType.NVarChar, 20).Value = LowRate
        cmd.Parameters.Add("@LowRate_Money", SqlDbType.NVarChar, 8).Value = LowRate_Money
        cmd.Parameters.Add("@Compute_C", SqlDbType.NVarChar, 1).Value = Compute_C

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function


    Public Function DeleteRelationMATERIAL(ByVal Meterial As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "Delete From RelationMeterial "
        sql &= " WHERE Meterial = @Meterial"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Meterial", SqlDbType.NVarChar, 18).Value = Meterial

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function
#End Region

    Public Sub GetImageStatus(ByRef imgVPS As Image, ByRef imgMRI As Image, ByRef imgMKT As Image, ByVal VPS_approve As String, ByVal MRI_approve As String, ByVal Marketing_approve As String, ByVal Status As String)
        If (VPS_approve & "" <> "") Then
            If (Status = "VC") Or (Status = "VP") Then
                imgVPS.ImageUrl = "~/Image/red.png"
            Else
                imgVPS.ImageUrl = "~/Image/green.png"
            End If
        Else
            imgVPS.ImageUrl = "~/Image/red.png"
        End If
        If (MRI_approve & "" <> "") Then
            If (Status = "MC") Or (Status = "MP") Then
                imgMRI.ImageUrl = "~/Image/red.png"
            Else
                imgMRI.ImageUrl = "~/Image/green.png"
            End If
        Else
            If (Status = "MO") Or (Status = "OA") Or (Status = "FN") Then
                imgMRI.ImageUrl = "~/Image/green.png"
            Else
                imgMRI.ImageUrl = "~/Image/red.png"
            End If
        End If
        If (Marketing_approve & "" <> "") Then
            imgMKT.ImageUrl = "~/Image/green.png"
        Else
            imgMKT.ImageUrl = "~/Image/red.png"
        End If
    End Sub

    Public Function GetStatusCancel(ByVal Status As String) As Boolean
        If (Status & "" = "CA") Or (Status & "" = "CV") Or (Status & "" = "CM") Or (Status & "" = "CR") Or (Status & "" = "CC") Then
            Return True
        Else
            Return False
        End If
    End Function
    Public Sub GetImageStatusMKT(ByRef imgProduct As Image, ByRef imgCustom As Image, ByRef imgFinance As Image, ByVal Product As String, ByVal Custom As String, ByVal Finance As String)
        If (Product = "Y") Then
            imgProduct.ImageUrl = "~/Image/green.png"
        Else
            imgProduct.ImageUrl = "~/Image/red.png"
        End If
        If (Custom = "Y") Then
            imgCustom.ImageUrl = "~/Image/green.png"
        Else
            imgCustom.ImageUrl = "~/Image/red.png"
        End If
        If (Finance = "Y") Then
            imgFinance.ImageUrl = "~/Image/green.png"
        Else
            imgFinance.ImageUrl = "~/Image/red.png"
        End If
    End Sub

    Public Function DeleteBooking_LogSheet_In(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "Delete From Booking_LogSheet_In "
        sql &= " WHERE Booking_no = @Booking_no"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBooking_LogSheet_Out(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "Delete From Booking_LogSheet_Out "
        sql &= " WHERE Booking_no = @Booking_no  ;"
        sql &= "Delete From Booking_LogSheet_Out_Product "
        sql &= " WHERE Booking_no = @Booking_no  ;"

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBooking_LogSheet_Tug(ByVal Booking_no As String, ByVal T As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "Delete From Booking_LogSheet_Tug "
        sql &= " WHERE Booking_no = @Booking_no "
        sql &= " AND Type = @Type "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Type", SqlDbType.NVarChar, 1).Value = T

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBooking_LogSheet_Out_Product(ByVal Booking_no As String, ByVal Product_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "Delete From Booking_LogSheet_Out_Product "
        sql &= " WHERE Booking_no = @Booking_no "
        sql &= " AND Product_no = @Product_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 1).Value = Product_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteBooking_LogSheet(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = "Delete From Booking_LogSheet "
        sql &= " WHERE Booking_no = @Booking_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_LogSheet(ByVal Booking_no As String, ByVal C_S As String, ByVal Draft_FOR As String, ByVal Draft_AFT As String, ByVal IMO_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Booking_LogSheet(Booking_no,C_S,Draft_FOR,Draft_AFT,IMO_no) "
        sql &= " VALUES(@Booking_no,@C_S,@Draft_FOR,@Draft_AFT,@IMO_no)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@C_S", SqlDbType.NVarChar, 50).Value = C_S
        cmd.Parameters.Add("@Draft_FOR", SqlDbType.NVarChar, 50).Value = Draft_FOR
        cmd.Parameters.Add("@Draft_AFT", SqlDbType.NVarChar, 50).Value = Draft_AFT
        cmd.Parameters.Add("@IMO_no", SqlDbType.NVarChar, 50).Value = IMO_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_LogSheet_Tug(ByVal Booking_no As String, ByVal Tug_Code As String, ByVal Tug_Name As String, ByVal Date_Time As String, ByVal Start_Time As String, ByVal End_Time As String, ByVal Hrs As String, ByVal Remark As String, ByVal T As String, ByVal Tug_Event As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Booking_LogSheet_Tug(Booking_no,Tug_Code,Tug_Name,Date_Time,Start_Time,End_Time,Hrs,Remark,Type,Tug_Event) "
        sql &= " VALUES(@Booking_no,@Tug_Code,@Tug_Name,@Date_Time,@Start_Time,@End_Time,@Hrs,@Remark,@Type,@Tug_Event)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Tug_Code", SqlDbType.NVarChar, 10).Value = Tug_Code
        cmd.Parameters.Add("@Tug_Name", SqlDbType.NVarChar, 500).Value = Tug_Name
        cmd.Parameters.Add("@Date_Time", SqlDbType.NVarChar, 12).Value = Date_Time
        cmd.Parameters.Add("@Start_Time", SqlDbType.NVarChar, 5).Value = Start_Time
        cmd.Parameters.Add("@End_Time", SqlDbType.NVarChar, 5).Value = End_Time
        cmd.Parameters.Add("@Hrs", SqlDbType.NVarChar, 5).Value = Hrs
        cmd.Parameters.Add("@Remark", SqlDbType.NVarChar, 2000).Value = Remark
        cmd.Parameters.Add("@Type", SqlDbType.NVarChar, 1).Value = T
        cmd.Parameters.Add("@Tug_Event", SqlDbType.NVarChar, 1).Value = Tug_Event

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_LogSheet_In(ByVal Booking_no As String, ByVal Commence_Date As String, ByVal Commence_Time As String, ByVal Commence_Remark As String, ByVal Last_Value As String, ByVal Last_Remark As String, ByVal ETA_Date As String, ByVal ETA_Time As String, ByVal ETA_Remark As String, ByVal Start_Value As String, ByVal Start_Remark As String, ByVal Anchor_Date As String, ByVal Anchor_Time As String, ByVal Anchor_Remark As String, ByVal Position_Value As String, ByVal Position_Remark As String, ByVal Tug_Value As String, ByVal Tug_Remark As String, ByVal Pilot As String, ByVal POB_Date As String, ByVal POB_Time As String, ByVal POB_Remark As String, ByVal Schedule_Date As String, ByVal Schedule_Time As String, ByVal Schedule_Remark As String, ByVal Berthing_Date As String, ByVal Berthing_TimeFrom As String, ByVal Berthing_TimeTo As String, ByVal Berthing_Remark As String, ByVal Addition As String, ByVal User_modify As String, ByVal NOR_Date As String, ByVal NOR_Time As String, ByVal Up_Date As String, ByVal Up_Time As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Booking_LogSheet_In(Booking_no,Commence_Date,Commence_Time,Commence_Remark,Last_Value,Last_Remark,ETA_Date,ETA_Time,ETA_Remark,Start_Value,Start_Remark,Anchor_Date,Anchor_Time,Anchor_Remark,Position_Value,Position_Remark,Tug_Value,Tug_Remark,Pilot,POB_Date,POB_Time,POB_Remark " & vbCrLf
        sql &= " ,Schedule_Date,Schedule_Time,Schedule_Remark,Berthing_Date,Berthing_TimeFrom,Berthing_TimeTo,Berthing_Remark,Addition,User_Modify,NOR_Date,NOR_Time,Up_Date,Up_Time)  " & vbCrLf
        sql &= " VALUES(@Booking_no,@Commence_Date,@Commence_Time,@Commence_Remark,@Last_Value,@Last_Remark,@ETA_Date,@ETA_Time,@ETA_Remark,@Start_Value,@Start_Remark,@Anchor_Date,@Anchor_Time,@Anchor_Remark,@Position_Value,@Position_Remark,@Tug_Value,@Tug_Remark,@Pilot,@POB_Date,@POB_Time,@POB_Remark " & vbCrLf
        sql &= " ,@Schedule_Date,@Schedule_Time,@Schedule_Remark,@Berthing_Date,@Berthing_TimeFrom,@Berthing_TimeTo,@Berthing_Remark,@Addition,@User_Modify,@NOR_Date,@NOR_Time,@Up_Date,@Up_Time) " & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Commence_Date", SqlDbType.NVarChar, 12).Value = Commence_Date
        cmd.Parameters.Add("@Commence_Time", SqlDbType.NVarChar, 5).Value = Commence_Time
        cmd.Parameters.Add("@Commence_Remark", SqlDbType.NVarChar, 2000).Value = Commence_Remark
        cmd.Parameters.Add("@Last_Value", SqlDbType.NVarChar, 500).Value = Last_Value
        cmd.Parameters.Add("@Last_Remark", SqlDbType.NVarChar, 2000).Value = Last_Remark
        cmd.Parameters.Add("@ETA_Date", SqlDbType.NVarChar, 12).Value = ETA_Date
        cmd.Parameters.Add("@ETA_Time", SqlDbType.NVarChar, 5).Value = ETA_Time
        cmd.Parameters.Add("@ETA_Remark", SqlDbType.NVarChar, 2000).Value = ETA_Remark
        cmd.Parameters.Add("@Start_Value", SqlDbType.NVarChar, 500).Value = Start_Value
        cmd.Parameters.Add("@Start_Remark", SqlDbType.NVarChar, 2000).Value = Start_Remark
        cmd.Parameters.Add("@Anchor_Date", SqlDbType.NVarChar, 12).Value = Anchor_Date
        cmd.Parameters.Add("@Anchor_Time", SqlDbType.NVarChar, 5).Value = Anchor_Time
        cmd.Parameters.Add("@Anchor_Remark", SqlDbType.NVarChar, 2000).Value = Anchor_Remark
        cmd.Parameters.Add("@Position_Value", SqlDbType.NVarChar, 500).Value = Position_Value
        cmd.Parameters.Add("@Position_Remark", SqlDbType.NVarChar, 2000).Value = Position_Remark
        cmd.Parameters.Add("@Tug_Value", SqlDbType.NVarChar, 500).Value = Tug_Value
        cmd.Parameters.Add("@Tug_Remark", SqlDbType.NVarChar, 2000).Value = Tug_Remark
        cmd.Parameters.Add("@Pilot", SqlDbType.NVarChar, 10).Value = Pilot
        cmd.Parameters.Add("@POB_Date", SqlDbType.NVarChar, 12).Value = POB_Date
        cmd.Parameters.Add("@POB_Time", SqlDbType.NVarChar, 5).Value = POB_Time
        cmd.Parameters.Add("@POB_Remark", SqlDbType.NVarChar, 2000).Value = POB_Remark
        cmd.Parameters.Add("@Schedule_Date", SqlDbType.NVarChar, 12).Value = Schedule_Date
        cmd.Parameters.Add("@Schedule_Time", SqlDbType.NVarChar, 5).Value = Schedule_Time
        cmd.Parameters.Add("@Schedule_Remark", SqlDbType.NVarChar, 2000).Value = Schedule_Remark
        cmd.Parameters.Add("@Berthing_Date", SqlDbType.NVarChar, 12).Value = Berthing_Date
        cmd.Parameters.Add("@Berthing_TimeFrom", SqlDbType.NVarChar, 5).Value = Berthing_TimeFrom
        cmd.Parameters.Add("@Berthing_TimeTo", SqlDbType.NVarChar, 5).Value = Berthing_TimeTo
        cmd.Parameters.Add("@Berthing_Remark", SqlDbType.NVarChar, 2000).Value = Berthing_Remark
        cmd.Parameters.Add("@Addition", SqlDbType.NVarChar, 4000).Value = Addition
        cmd.Parameters.Add("@User_Modify", SqlDbType.NVarChar, 50).Value = User_modify
        cmd.Parameters.Add("@NOR_Date", SqlDbType.NVarChar, 12).Value = NOR_Date
        cmd.Parameters.Add("@NOR_Time", SqlDbType.NVarChar, 5).Value = NOR_Time
        cmd.Parameters.Add("@Up_Date", SqlDbType.NVarChar, 12).Value = Up_Date
        cmd.Parameters.Add("@Up_Time", SqlDbType.NVarChar, 5).Value = Up_Time

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_LogSheet_Out(ByVal Booking_no As String, ByVal Pilot As String, ByVal POB_Date As String, ByVal POB_Time As String, ByVal POB_Remark As String, ByVal Tug_Value As String, ByVal Tug_Remark As String, ByVal Last_Date As String, ByVal Last_TimeFrom As String, ByVal Last_Time As String, ByVal Last_Remark As String, ByVal Next_Value As String, ByVal Next_Remark As String, ByVal End_Date As String, ByVal End_Time As String, ByVal End_Remark As String, ByVal Addition As String, ByVal User_Modify As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Booking_LogSheet_Out(Booking_no" & vbCrLf
        sql &= " ,Pilot,POB_Date,POB_Time,POB_Remark,Tug_Value,Tug_Remark,Last_Date,Last_TimeFrom,Last_Time,Last_Remark,Next_Value,Next_Remark,End_Date,End_Time,End_Remark,Addition,User_Modify,Status )  " & vbCrLf
        sql &= " VALUES(@Booking_no" & vbCrLf
        sql &= " ,@Pilot,@POB_Date,@POB_Time,@POB_Remark,@Tug_Value,@Tug_Remark,@Last_Date,@Last_TimeFrom,@Last_Time,@Last_Remark,@Next_Value,@Next_Remark,@End_Date,@End_Time,@End_Remark,@Addition,@User_Modify,@Status) " & vbCrLf
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Pilot", SqlDbType.NVarChar, 5).Value = Pilot
        cmd.Parameters.Add("@POB_Date", SqlDbType.NVarChar, 12).Value = POB_Date
        cmd.Parameters.Add("@POB_Time", SqlDbType.NVarChar, 5).Value = POB_Time
        cmd.Parameters.Add("@POB_Remark", SqlDbType.NVarChar, 2000).Value = POB_Remark
        cmd.Parameters.Add("@Tug_Value", SqlDbType.NVarChar, 500).Value = Tug_Value
        cmd.Parameters.Add("@Tug_Remark", SqlDbType.NVarChar, 2000).Value = Tug_Remark
        cmd.Parameters.Add("@Last_Date", SqlDbType.NVarChar, 12).Value = Last_Date
        cmd.Parameters.Add("@Last_TimeFrom", SqlDbType.NVarChar, 5).Value = Last_TimeFrom
        cmd.Parameters.Add("@Last_Time", SqlDbType.NVarChar, 5).Value = Last_Time
        cmd.Parameters.Add("@Last_Remark", SqlDbType.NVarChar, 2000).Value = Last_Remark
        cmd.Parameters.Add("@Next_Value", SqlDbType.NVarChar, 500).Value = Next_Value
        cmd.Parameters.Add("@Next_Remark", SqlDbType.NVarChar, 2000).Value = Next_Remark
        cmd.Parameters.Add("@End_Date", SqlDbType.NVarChar, 12).Value = End_Date
        cmd.Parameters.Add("@End_Time", SqlDbType.NVarChar, 5).Value = End_Time
        cmd.Parameters.Add("@End_Remark", SqlDbType.NVarChar, 2000).Value = End_Remark
        cmd.Parameters.Add("@Addition", SqlDbType.NVarChar, 4000).Value = Addition
        cmd.Parameters.Add("@User_Modify", SqlDbType.NVarChar, 50).Value = User_Modify
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 1).Value = Status
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertBooking_LogSheet_Out_Product(ByVal Booking_no As String, ByVal Product_no As String, ByVal Connect_Date As String, ByVal Connect_TimeFrom As String, ByVal Connect_TimeTo As String, ByVal Connect_Remark As String, ByVal Dis_Date As String, ByVal Dis_TimeFrom As String, ByVal Dis_TimeTo As String, ByVal Dis_Remark As String, ByVal ETD_Date As String, ByVal ETD_Time As String, ByVal ETD_Remark As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Booking_LogSheet_Out_Product(Booking_no,Product_no,Connect_Date,Connect_TimeFrom,Connect_TimeTo,Connect_Remark,Dis_Date,Dis_TimeFrom,Dis_TimeTo,Dis_Remark,ETD_Date,ETD_Time,ETD_Remark) "
        sql &= " VALUES(@Booking_no,@Product_no,@Connect_Date,@Connect_TimeFrom,@Connect_TimeTo,@Connect_Remark,@Dis_Date,@Dis_TimeFrom,@Dis_TimeTo,@Dis_Remark,@ETD_Date,@ETD_Time,@ETD_Remark)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Connect_Date", SqlDbType.NVarChar, 12).Value = Connect_Date
        cmd.Parameters.Add("@Connect_TimeFrom", SqlDbType.NVarChar, 5).Value = Connect_TimeFrom
        cmd.Parameters.Add("@Connect_TimeTo", SqlDbType.NVarChar, 5).Value = Connect_TimeTo
        cmd.Parameters.Add("@Connect_Remark", SqlDbType.NVarChar, 2000).Value = Connect_Remark
        cmd.Parameters.Add("@Dis_Date", SqlDbType.NVarChar, 12).Value = Dis_Date
        cmd.Parameters.Add("@Dis_TimeFrom", SqlDbType.NVarChar, 5).Value = Dis_TimeFrom
        cmd.Parameters.Add("@Dis_TimeTo", SqlDbType.NVarChar, 5).Value = Dis_TimeTo
        cmd.Parameters.Add("@Dis_Remark", SqlDbType.NVarChar, 2000).Value = Dis_Remark
        cmd.Parameters.Add("@ETD_Date", SqlDbType.NVarChar, 12).Value = ETD_Date
        cmd.Parameters.Add("@ETD_Time", SqlDbType.NVarChar, 5).Value = ETD_Time
        cmd.Parameters.Add("@ETD_Remark", SqlDbType.NVarChar, 2000).Value = ETD_Remark
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Delay(ByVal Booking_no As String, ByVal Date_From As String, ByVal Date_To As String, ByVal Time_From As String, ByVal Time_To As String, ByVal Casue_Delay As String, ByVal Delay_Time As String, ByVal Cause_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Delay(Booking_no,Date_From,Date_To,Time_From,Time_To,Cause_Delay,Delay_Time,Cause_Code) "
        sql &= " VALUES(@Booking_no,@Date_From,@Date_To,@Time_From,@Time_To,@Cause_Delay,@Delay_Time,@Cause_Code)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Date_From", SqlDbType.NVarChar, 8).Value = Date_From
        cmd.Parameters.Add("@Date_To", SqlDbType.NVarChar, 8).Value = Date_To
        cmd.Parameters.Add("@Time_From", SqlDbType.NVarChar, 5).Value = Time_From
        cmd.Parameters.Add("@Time_To", SqlDbType.NVarChar, 5).Value = Time_To
        cmd.Parameters.Add("@Cause_Delay", SqlDbType.NVarChar, 500).Value = Casue_Delay
        cmd.Parameters.Add("@Delay_Time", SqlDbType.NVarChar, 5).Value = Delay_Time
        cmd.Parameters.Add("@Cause_Code", SqlDbType.NVarChar, 10).Value = Cause_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Remark(ByVal Booking_no As String, ByVal Remark As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Remark(Booking_no,Remark) "
        sql &= " VALUES(@Booking_no,@Remark)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Remark", SqlDbType.NVarChar, 500).Value = Remark

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Vessel(ByVal Booking_no As String, ByVal Third_Party As String, ByVal Concern As String, ByVal Tank_From As String, ByVal Tank_To As String, ByVal Figure As String, ByVal Lab As String, ByVal Sampling_From As String, ByVal Sampling_To As String, ByVal Labafter As String, ByVal Tankafter_From As String, ByVal Tankafter_To As String, ByVal Figureafter As String, ByVal Document_Time As String, ByVal Bunker_Point As String, ByVal Bunker_Time As String, ByVal Bunker_Standard_Date As String, ByVal Bunker_Standard_Time As String, ByVal Bunker_Actual_Date As String, ByVal Bunker_Actual_Time As String, ByVal Bunker_Actual_TimeTo As String, ByVal Depart_Standard_Date As String, ByVal Depart_Standard_Time As String, ByVal Depart_Actual_Date As String, ByVal Depart_Actual_Time As String, ByVal Tug_Before As String, ByVal Tug_After As String, ByVal NOR_Date As String, ByVal NOR_Time As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Vessel(Booking_no,Third_Party,Concern,Tank_From,Tank_To,Figure,Lab,Sampling_From,Sampling_To,Labafter,Tankafter_From,Tankafter_To,Figureafter,Document_Time,Bunker_Point,Bunker_Time,Bunker_Standard_Date,Bunker_Standard_Time,Bunker_Actual_Date,Bunker_Actual_Time,Bunker_Actual_TimeTo,Depart_Standard_Date,Depart_Standard_Time,Depart_Actual_Date,Depart_Actual_Time,Tug_Before,Tug_After,NOR_Date,NOR_Time,Status) "
        sql &= " VALUES(@Booking_no,@Third_Party,@Concern,@Tank_From,@Tank_To,@Figure,@Lab,@Sampling_From,@Sampling_To,@Labafter,@Tankafter_From,@Tankafter_To,@Figureafter,@Document_Time,@Bunker_Point,@Bunker_Time,@Bunker_Standard_Date,@Bunker_Standard_Time,@Bunker_Actual_Date,@Bunker_Actual_Time,@Bunker_Actual_TimeTo,@Depart_Standard_Date,@Depart_Standard_Time,@Depart_Actual_Date,@Depart_Actual_Time,@Tug_Before,@Tug_After,@NOR_Date,@NOR_Time,@Status)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Third_Party", SqlDbType.NVarChar, 200).Value = Third_Party
        cmd.Parameters.Add("@Concern", SqlDbType.NVarChar, 5).Value = Concern
        cmd.Parameters.Add("@Tank_From", SqlDbType.NVarChar, 5).Value = Tank_From
        cmd.Parameters.Add("@Tank_To", SqlDbType.NVarChar, 5).Value = Tank_To
        cmd.Parameters.Add("@Figure", SqlDbType.NVarChar, 5).Value = Figure
        cmd.Parameters.Add("@Lab", SqlDbType.NVarChar, 5).Value = Lab
        cmd.Parameters.Add("@Sampling_From", SqlDbType.NVarChar, 5).Value = Sampling_From
        cmd.Parameters.Add("@Sampling_To", SqlDbType.NVarChar, 5).Value = Sampling_To
        cmd.Parameters.Add("@Labafter", SqlDbType.NVarChar, 5).Value = Labafter
        cmd.Parameters.Add("@Tankafter_From", SqlDbType.NVarChar, 5).Value = Tankafter_From
        cmd.Parameters.Add("@Tankafter_To", SqlDbType.NVarChar, 5).Value = Tankafter_To
        cmd.Parameters.Add("@Figureafter", SqlDbType.NVarChar, 5).Value = Figureafter
        cmd.Parameters.Add("@Document_Time", SqlDbType.NVarChar, 5).Value = Document_Time
        cmd.Parameters.Add("@Bunker_Point", SqlDbType.NVarChar, 5).Value = Bunker_Point
        cmd.Parameters.Add("@Bunker_Time", SqlDbType.NVarChar, 5).Value = Bunker_Time
        cmd.Parameters.Add("@Bunker_Standard_Date", SqlDbType.NVarChar, 12).Value = Bunker_Standard_Date
        cmd.Parameters.Add("@Bunker_Standard_Time", SqlDbType.NVarChar, 5).Value = Bunker_Standard_Time
        cmd.Parameters.Add("@Bunker_Actual_Date", SqlDbType.NVarChar, 12).Value = Bunker_Actual_Date
        cmd.Parameters.Add("@Bunker_Actual_Time", SqlDbType.NVarChar, 5).Value = Bunker_Actual_Time
        cmd.Parameters.Add("@Bunker_Actual_TimeTo", SqlDbType.NVarChar, 5).Value = Bunker_Actual_TimeTo
        cmd.Parameters.Add("@Depart_Standard_Date", SqlDbType.NVarChar, 12).Value = Depart_Standard_Date
        cmd.Parameters.Add("@Depart_Standard_Time", SqlDbType.NVarChar, 5).Value = Depart_Standard_Time
        cmd.Parameters.Add("@Depart_Actual_Date", SqlDbType.NVarChar, 12).Value = Depart_Actual_Date
        cmd.Parameters.Add("@Depart_Actual_Time", SqlDbType.NVarChar, 5).Value = Depart_Actual_Time
        cmd.Parameters.Add("@Tug_Before", SqlDbType.NVarChar, 2000).Value = Tug_Before
        cmd.Parameters.Add("@Tug_After", SqlDbType.NVarChar, 2000).Value = Tug_After
        cmd.Parameters.Add("@NOR_Date", SqlDbType.NVarChar, 15).Value = NOR_Date
        cmd.Parameters.Add("@NOR_Time", SqlDbType.NVarChar, 5).Value = NOR_Time
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 1).Value = Status
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Vessel_Bulk(ByVal Booking_no As String, ByVal Third_Party As String, ByVal Depart_Actual_Date As String, ByVal Depart_Actual_Time As String, ByVal Tug_Before As String, ByVal Tug_After As String, ByVal Ship_Wharf As String, ByVal Ship_Fender As String, ByVal Company As String, ByVal Company_Person As String, ByVal Draft_FOR As String, ByVal Draft_AFT As String, ByVal Initial_Company As String, ByVal Initial_DateFrom As String, ByVal Initial_DateTo As String, ByVal Initial_From As String, ByVal Initial_To As String, ByVal Draft_FOR_Out As String, ByVal Draft_AFT_Out As String, ByVal Final_Company As String, ByVal Final_DateFrom As String, ByVal Final_DateTo As String, ByVal Final_From As String, ByVal Final_To As String, ByVal Ship_Wharf_Out As String, ByVal Ship_Fender_Out As String, ByVal Company_Person_Out As String, ByVal NOR_Date As String, ByVal NOR_Time As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Vessel(Booking_no,Third_Party,Depart_Actual_Date,Depart_Actual_Time,Tug_Before,Tug_After,Ship_Wharf,Ship_Fender,Company,Company_Person,Draft_FOR,Draft_AFT,Initial_Company,Initial_DateFrom,Initial_DateTo,Initial_From,Initial_To,Draft_FOR_Out,Draft_AFT_Out,Final_Company,Final_DateFrom,Final_DateTo,Final_From,Final_To,Ship_Wharf_Out,Ship_Fender_Out,Company_Person_Out,NOR_Date,NOR_Time,Status) "
        sql &= " VALUES(@Booking_no,@Third_Party,@Depart_Actual_Date,@Depart_Actual_Time,@Tug_Before,@Tug_After,@Ship_Wharf,@Ship_Fender,@Company,@Company_Person,@Draft_FOR,@Draft_AFT,@Initial_Company,@Initial_DateFrom,@Initial_DateTo,@Initial_From,@Initial_To,@Draft_FOR_Out,@Draft_AFT_Out,@Final_Company,@Final_DateFrom,@Final_DateTo,@Final_From,@Final_To,@Ship_Wharf_Out,@Ship_Fender_Out,@Company_Person_Out,@NOR_Date,@NOR_Time,@Status)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Third_Party", SqlDbType.NVarChar, 200).Value = Third_Party
        cmd.Parameters.Add("@Depart_Actual_Date", SqlDbType.NVarChar, 12).Value = Depart_Actual_Date
        cmd.Parameters.Add("@Depart_Actual_Time", SqlDbType.NVarChar, 5).Value = Depart_Actual_Time
        cmd.Parameters.Add("@Tug_Before", SqlDbType.NVarChar, 2000).Value = Tug_Before
        cmd.Parameters.Add("@Tug_After", SqlDbType.NVarChar, 2000).Value = Tug_After
        cmd.Parameters.Add("@Ship_Wharf", SqlDbType.NVarChar, 10).Value = Ship_Wharf
        cmd.Parameters.Add("@Ship_Fender", SqlDbType.NVarChar, 10).Value = Ship_Fender

        cmd.Parameters.Add("@Company", SqlDbType.NVarChar, 500).Value = Company
        cmd.Parameters.Add("@Company_Person", SqlDbType.NVarChar, 10).Value = Company_Person
        cmd.Parameters.Add("@Draft_FOR", SqlDbType.NVarChar, 10).Value = Draft_FOR
        cmd.Parameters.Add("@Draft_AFT", SqlDbType.NVarChar, 10).Value = Draft_AFT

        cmd.Parameters.Add("@Initial_Company", SqlDbType.NVarChar, 500).Value = Initial_Company
        cmd.Parameters.Add("@Initial_DateFrom", SqlDbType.NVarChar, 15).Value = Initial_DateFrom
        cmd.Parameters.Add("@Initial_DateTo", SqlDbType.NVarChar, 15).Value = Initial_DateTo
        cmd.Parameters.Add("@Initial_From", SqlDbType.NVarChar, 5).Value = Initial_From
        cmd.Parameters.Add("@Initial_To", SqlDbType.NVarChar, 5).Value = Initial_To
        cmd.Parameters.Add("@Draft_FOR_Out", SqlDbType.NVarChar, 10).Value = Draft_FOR_Out
        cmd.Parameters.Add("@Draft_AFT_Out", SqlDbType.NVarChar, 10).Value = Draft_AFT_Out

        cmd.Parameters.Add("@Final_Company", SqlDbType.NVarChar, 500).Value = Final_Company
        cmd.Parameters.Add("@Final_DateFrom", SqlDbType.NVarChar, 15).Value = Final_DateFrom
        cmd.Parameters.Add("@Final_DateTo", SqlDbType.NVarChar, 15).Value = Final_DateTo
        cmd.Parameters.Add("@Final_From", SqlDbType.NVarChar, 5).Value = Final_From
        cmd.Parameters.Add("@Final_To", SqlDbType.NVarChar, 5).Value = Final_To
        cmd.Parameters.Add("@Ship_Wharf_Out", SqlDbType.NVarChar, 10).Value = Ship_Wharf_Out
        cmd.Parameters.Add("@Ship_Fender_Out", SqlDbType.NVarChar, 10).Value = Ship_Fender_Out
        cmd.Parameters.Add("@Company_Person_Out", SqlDbType.NVarChar, 10).Value = Company_Person_Out

        cmd.Parameters.Add("@NOR_Date", SqlDbType.NVarChar, 15).Value = NOR_Date
        cmd.Parameters.Add("@NOR_Time", SqlDbType.NVarChar, 5).Value = NOR_Time
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 1).Value = Status
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertAction_Operation(ByVal A_Code As String, ByVal Booking_no As String, ByVal A_Action As String, ByVal A_Date As String, ByVal A_Time As String, ByVal A_By As String, ByVal A_Username As String, ByVal A_Description As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Action_Operation(A_Code,Booking_no,A_Action,A_Date,A_Time,A_By,A_Username,A_Description) "
        sql &= " VALUES(@A_Code,@Booking_no,@A_Action,@A_Date,@A_Time,@A_By,@A_Username,@A_Description)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@A_Code", SqlDbType.NVarChar, 10).Value = A_Code
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@A_Action", SqlDbType.NVarChar, 20).Value = A_Action
        cmd.Parameters.Add("@A_Date", SqlDbType.NVarChar, 30).Value = A_Date
        cmd.Parameters.Add("@A_Time", SqlDbType.NVarChar, 5).Value = A_Time
        cmd.Parameters.Add("@A_By", SqlDbType.NVarChar, 50).Value = A_By
        cmd.Parameters.Add("@A_Username", SqlDbType.NVarChar, 50).Value = A_Username
        cmd.Parameters.Add("@A_Description", SqlDbType.NVarChar, 500).Value = A_Description

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertAdd_Tariff_New(ByVal Booking_no As String, ByVal Material As String, ByVal Count As String, ByVal _Event As String, ByVal Status As String, ByVal Action_By As String, ByVal Action_Date As String, ByVal Action_Time As String, ByVal Description_ByCustomer As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Add_Tariff_New(Booking_no,Material,Count,Event,Status,Action_By,Action_Date,Action_Time,Description_ByCustomer) "
        sql &= " VALUES(@Booking_no,@Material,@Count,@Event,@Status,@Action_By,@Action_Date,@Action_Time,@Description_ByCustomer)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Material", SqlDbType.NVarChar, 18).Value = Material
        cmd.Parameters.Add("@Count", SqlDbType.NVarChar, 10).Value = Count
        cmd.Parameters.Add("@Event", SqlDbType.NVarChar, 1).Value = _Event
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 1).Value = Status
        cmd.Parameters.Add("@Action_By", SqlDbType.NVarChar, 50).Value = Action_By
        cmd.Parameters.Add("@Action_Date", SqlDbType.NVarChar, 15).Value = Action_Date
        cmd.Parameters.Add("@Action_Time", SqlDbType.NVarChar, 5).Value = Action_Time
        cmd.Parameters.Add("@Description_ByCustomer", SqlDbType.NVarChar, 500).Value = Description_ByCustomer
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATEAdd_Tariff_NewStatus(ByVal Booking_no As String, ByVal Status As String, ByVal Action_By As String, ByVal Action_Date As String, ByVal Action_Time As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Add_Tariff_New SET Status = @Status,Action_By = @Action_By,Action_Date = @Action_Date,Action_Time = @Action_Time "
        sql &= " WHERE Booking_no = @Booking_no"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 1).Value = Status
        cmd.Parameters.Add("@Action_By", SqlDbType.NVarChar, 50).Value = Action_By
        cmd.Parameters.Add("@Action_Date", SqlDbType.NVarChar, 15).Value = Action_Date
        cmd.Parameters.Add("@Action_Time", SqlDbType.NVarChar, 5).Value = Action_Time
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATELoad_Unload_Vessel_Status(ByVal Booking_no As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Load_Unload_Vessel SET"
        sql &= " Status = @Status WHERE Booking_no = @Booking_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 200).Value = Status

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UPDATEBooking_LogSheet_OutStatus(ByVal Booking_no As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Booking_LogSheet_Out SET"
        sql &= " Status = @Status WHERE Booking_no = @Booking_no "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 200).Value = Status

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteDaily_LCT(ByVal Booking_no As String, ByVal Product_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Daily_LCT "
        sql &= " Where Booking_no = @Booking_no and Product_no = @Product_no"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertDaily_LCT(ByVal Booking_no As String, ByVal Product_no As String, ByVal Acceptance As String, ByVal Demurrage As String, ByVal Pig As String, ByVal FW As String, ByVal Truck As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Daily_LCT(Booking_no,Product_no,Acceptance,Demurrage,Pig,FW,Truck)"
        sql &= " VALUES(@Booking_no,@Product_no,@Acceptance,@Demurrage,@Pig,@FW,@Truck) "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@Acceptance", SqlDbType.NVarChar, 2000).Value = Acceptance
        cmd.Parameters.Add("@Demurrage", SqlDbType.NVarChar, 2000).Value = Demurrage
        cmd.Parameters.Add("@Pig", SqlDbType.NVarChar, 2000).Value = Pig
        cmd.Parameters.Add("@FW", SqlDbType.NVarChar, 2000).Value = FW
        cmd.Parameters.Add("@Truck", SqlDbType.NVarChar, 2000).Value = Truck

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Product(ByVal Booking_no As String, ByVal Product_no As String, ByVal LU_BL As String, ByVal LU_BLMT As String, ByVal LU_Fill_From As String, ByVal LU_Fill_To As String, ByVal LU_Connect_Date As String, ByVal LU_Connect_From As String, ByVal LU_Connect_To As String, ByVal LU_StartStandard_Date As String, ByVal LU_StartStandard_Time As String, ByVal LU_StartActual_Date As String, ByVal LU_StartActual_Time As String, ByVal LU_StopStandard_Date As String, ByVal LU_StopStandard_Time As String, ByVal LU_StopActual_Date As String, ByVal LU_StopActual_Time As String, ByVal LU_SL As String, ByVal LU_SLMT As String, ByVal LU_Fillafter_From As String, ByVal LU_Fillafter_To As String, ByVal LU_Disconnect_Date As String, ByVal LU_Disconnect_From As String, ByVal LU_Disconnect_To As String, ByVal API_Shore As String, ByVal API_Ship As String, ByVal Vis_Shore As String, ByVal Vis_Ship As String, ByVal LU_SU As String, ByVal LU_SUMT As String, ByVal LU_ShoreRecieve As String, ByVal LU_ShoreRecieveMT As String, ByVal Plus_Tank As String, ByVal Product_index As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Product(Booking_no,Product_no,LU_BL,LU_BLMT,LU_Fill_From,LU_Fill_To,LU_Connect_Date,LU_Connect_From,LU_Connect_To,LU_StartStandard_Date,LU_StartStandard_Time,LU_StartActual_Date,LU_StartActual_Time,LU_StopStandard_Date,LU_StopStandard_Time,LU_StopActual_Date,LU_StopActual_Time,LU_SL,LU_SLMT,LU_Fillafter_From,LU_Fillafter_To,LU_Disconnect_Date,LU_Disconnect_From,LU_Disconnect_To,API_Shore,API_Ship,Vis_Shore,Vis_Ship,LU_SU,LU_SUMT,LU_ShoreRecieve,LU_ShoreRecieveMT,Plus_Tank,BP_Code) "
        sql &= " VALUES(@Booking_no,@Product_no,@LU_BL,@LU_BLMT,@LU_Fill_From,@LU_Fill_To,@LU_Connect_Date,@LU_Connect_From,@LU_Connect_To,@LU_StartStandard_Date,@LU_StartStandard_Time,@LU_StartActual_Date,@LU_StartActual_Time,@LU_StopStandard_Date,@LU_StopStandard_Time,@LU_StopActual_Date,@LU_StopActual_Time,@LU_SL,@LU_SLMT,@LU_Fillafter_From,@LU_Fillafter_To,@LU_Disconnect_Date,@LU_Disconnect_From,@LU_Disconnect_To,@API_Shore,@API_Ship,@Vis_Shore,@Vis_Ship,@LU_SU,@LU_SUMT,@LU_ShoreRecieve,@LU_ShoreRecieveMT,@Plus_Tank,@BP_Code) "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@LU_BL", SqlDbType.NVarChar, 20).Value = LU_BL
        cmd.Parameters.Add("@LU_BLMT", SqlDbType.NVarChar, 20).Value = LU_BLMT
        cmd.Parameters.Add("@LU_Fill_From", SqlDbType.NVarChar, 5).Value = LU_Fill_From
        cmd.Parameters.Add("@LU_Fill_To", SqlDbType.NVarChar, 5).Value = LU_Fill_To
        cmd.Parameters.Add("@LU_Connect_Date", SqlDbType.NVarChar, 12).Value = LU_Connect_Date
        cmd.Parameters.Add("@LU_Connect_From", SqlDbType.NVarChar, 5).Value = LU_Connect_From
        cmd.Parameters.Add("@LU_Connect_To", SqlDbType.NVarChar, 5).Value = LU_Connect_To
        cmd.Parameters.Add("@LU_StartStandard_Date", SqlDbType.NVarChar, 12).Value = LU_StartStandard_Date
        cmd.Parameters.Add("@LU_StartStandard_Time", SqlDbType.NVarChar, 5).Value = LU_StartStandard_Time
        cmd.Parameters.Add("@LU_StartActual_Date", SqlDbType.NVarChar, 12).Value = LU_StartActual_Date
        cmd.Parameters.Add("@LU_StartActual_Time", SqlDbType.NVarChar, 5).Value = LU_StartActual_Time
        cmd.Parameters.Add("@LU_StopStandard_Date", SqlDbType.NVarChar, 12).Value = LU_StopStandard_Date
        cmd.Parameters.Add("@LU_StopStandard_Time", SqlDbType.NVarChar, 5).Value = LU_StopStandard_Time
        cmd.Parameters.Add("@LU_StopActual_Date", SqlDbType.NVarChar, 12).Value = LU_StopActual_Date
        cmd.Parameters.Add("@LU_StopActual_Time", SqlDbType.NVarChar, 5).Value = LU_StopActual_Time
        cmd.Parameters.Add("@LU_SL", SqlDbType.NVarChar, 20).Value = LU_SL
        cmd.Parameters.Add("@LU_SLMT", SqlDbType.NVarChar, 20).Value = LU_SLMT
        cmd.Parameters.Add("@LU_Fillafter_From", SqlDbType.NVarChar, 5).Value = LU_Fillafter_From
        cmd.Parameters.Add("@LU_Fillafter_To", SqlDbType.NVarChar, 5).Value = LU_Fillafter_To
        cmd.Parameters.Add("@LU_Disconnect_Date", SqlDbType.NVarChar, 12).Value = LU_Disconnect_Date
        cmd.Parameters.Add("@LU_Disconnect_From", SqlDbType.NVarChar, 5).Value = LU_Disconnect_From
        cmd.Parameters.Add("@LU_Disconnect_To", SqlDbType.NVarChar, 5).Value = LU_Disconnect_To

        cmd.Parameters.Add("@API_Shore", SqlDbType.NVarChar, 20).Value = API_Shore
        cmd.Parameters.Add("@API_Ship", SqlDbType.NVarChar, 20).Value = API_Ship
        cmd.Parameters.Add("@Vis_Shore", SqlDbType.NVarChar, 20).Value = Vis_Shore
        cmd.Parameters.Add("@Vis_Ship", SqlDbType.NVarChar, 20).Value = Vis_Ship

        cmd.Parameters.Add("@LU_SU", SqlDbType.NVarChar, 20).Value = LU_SU
        cmd.Parameters.Add("@LU_SUMT", SqlDbType.NVarChar, 20).Value = LU_SUMT
        cmd.Parameters.Add("@LU_ShoreRecieve", SqlDbType.NVarChar, 20).Value = LU_ShoreRecieve
        cmd.Parameters.Add("@LU_ShoreRecieveMT", SqlDbType.NVarChar, 20).Value = LU_ShoreRecieveMT

        cmd.Parameters.Add("@Plus_Tank", SqlDbType.NVarChar, 2).Value = Plus_Tank

        cmd.Parameters.Add("@BP_Code", SqlDbType.NVarChar, 25).Value = Booking_no & Product_no & Product_index

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Product_Bulk(ByVal Booking_no As String, ByVal Product_no As String, ByVal LU_StartStandard_Date As String, ByVal LU_StartStandard_Time As String, ByVal LU_StartActual_Date As String, ByVal LU_StartActual_Time As String, ByVal LU_StopStandard_Date As String, ByVal LU_StopStandard_Time As String, ByVal LU_StopActual_Date As String, ByVal LU_StopActual_Time As String, ByVal BU_Product_Catalog As String, ByVal BU_Bill As String, ByVal BU_Draft As String, ByVal BU_Manifest As String, ByVal BU_Truck As String, ByVal BP_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Product(Booking_no,Product_no,LU_StartStandard_Date,LU_StartStandard_Time,LU_StartActual_Date,LU_StartActual_Time,LU_StopStandard_Date,LU_StopStandard_Time,LU_StopActual_Date,LU_StopActual_Time,BU_Product_Catalog,BU_Bill,BU_Draft,BU_Manifest,BU_Truck,BP_Code) "
        sql &= " VALUES(@Booking_no,@Product_no,@LU_StartStandard_Date,@LU_StartStandard_Time,@LU_StartActual_Date,@LU_StartActual_Time,@LU_StopStandard_Date,@LU_StopStandard_Time,@LU_StopActual_Date,@LU_StopActual_Time,@BU_Product_Catalog,@BU_Bill,@BU_Draft,@BU_Manifest,@BU_Truck,@BP_Code) "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@LU_StartStandard_Date", SqlDbType.NVarChar, 12).Value = LU_StartStandard_Date
        cmd.Parameters.Add("@LU_StartStandard_Time", SqlDbType.NVarChar, 5).Value = LU_StartStandard_Time
        cmd.Parameters.Add("@LU_StartActual_Date", SqlDbType.NVarChar, 12).Value = LU_StartActual_Date
        cmd.Parameters.Add("@LU_StartActual_Time", SqlDbType.NVarChar, 5).Value = LU_StartActual_Time
        cmd.Parameters.Add("@LU_StopStandard_Date", SqlDbType.NVarChar, 12).Value = LU_StopStandard_Date
        cmd.Parameters.Add("@LU_StopStandard_Time", SqlDbType.NVarChar, 5).Value = LU_StopStandard_Time
        cmd.Parameters.Add("@LU_StopActual_Date", SqlDbType.NVarChar, 12).Value = LU_StopActual_Date
        cmd.Parameters.Add("@LU_StopActual_Time", SqlDbType.NVarChar, 5).Value = LU_StopActual_Time

        cmd.Parameters.Add("@BU_Product_Catalog", SqlDbType.NVarChar, 50).Value = BU_Product_Catalog
        cmd.Parameters.Add("@BU_Bill", SqlDbType.NVarChar, 50).Value = BU_Bill
        cmd.Parameters.Add("@BU_Draft", SqlDbType.NVarChar, 50).Value = BU_Draft
        cmd.Parameters.Add("@BU_Manifest", SqlDbType.NVarChar, 50).Value = BU_Manifest
        cmd.Parameters.Add("@BU_Truck", SqlDbType.NVarChar, 50).Value = BU_Truck
        cmd.Parameters.Add("@BP_Code", SqlDbType.NVarChar, 25).Value = BP_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Product_BulkValue(ByVal Booking_no As String, ByVal Product_no As String, ByVal _Date As String, ByVal _DateSort As String, ByVal _Time As String, ByVal _STruck As String, ByVal _Truck6 As String, ByVal _Truck810 As String, ByVal _Trailer As String, ByVal _Trailer2 As String, ByVal _M As String, ByVal _P As String, ByVal _B As String, ByVal _T As String, ByVal _C As String, ByVal _L As String, ByVal _R As String, ByVal _Remark As String, ByVal _Date2 As String, ByVal _Time2 As String, ByVal BP_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Product_Bulk(Booking_no,Product_no,_Date,_DateSort,_Time,_STruck,_Truck6,_Truck810,_Trailer,_Trailer2,_M,_P,_B,_T,_C,_L,_R,_Remark,_Date2,_Time2,BP_Code) "
        sql &= " VALUES(@Booking_no,@Product_no,@_Date,@_DateSort,@_Time,@_STruck,@_Truck6,@_Truck810,@_Trailer,@_Trailer2,@_M,@_P,@_B,@_T,@_C,@_L,@_R,@_Remark,@_Date2,@_Time2,@BP_Code) "
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@_Date", SqlDbType.NVarChar, 12).Value = _Date
        cmd.Parameters.Add("@_DateSort", SqlDbType.NVarChar, 20).Value = _DateSort
        cmd.Parameters.Add("@_Time", SqlDbType.NVarChar, 5).Value = _Time
        cmd.Parameters.Add("@_STruck", SqlDbType.NVarChar, 10).Value = _STruck
        cmd.Parameters.Add("@_Truck6", SqlDbType.NVarChar, 10).Value = _Truck6
        cmd.Parameters.Add("@_Truck810", SqlDbType.NVarChar, 10).Value = _Truck810
        cmd.Parameters.Add("@_Trailer", SqlDbType.NVarChar, 10).Value = _Trailer
        cmd.Parameters.Add("@_Trailer2", SqlDbType.NVarChar, 10).Value = _Trailer2
        cmd.Parameters.Add("@_Date2", SqlDbType.NVarChar, 12).Value = _Date2
        cmd.Parameters.Add("@_Time2", SqlDbType.NVarChar, 5).Value = _Time2

        cmd.Parameters.Add("@_M", SqlDbType.NVarChar, 10).Value = _M
        cmd.Parameters.Add("@_P", SqlDbType.NVarChar, 10).Value = _P
        cmd.Parameters.Add("@_B", SqlDbType.NVarChar, 10).Value = _B
        cmd.Parameters.Add("@_T", SqlDbType.NVarChar, 10).Value = _T
        cmd.Parameters.Add("@_C", SqlDbType.NVarChar, 10).Value = _C
        cmd.Parameters.Add("@_L", SqlDbType.NVarChar, 10).Value = _L
        cmd.Parameters.Add("@_R", SqlDbType.NVarChar, 10).Value = _R
        cmd.Parameters.Add("@_Remark", SqlDbType.NVarChar, 2000).Value = _Remark
        cmd.Parameters.Add("@BP_Code", SqlDbType.NVarChar, 25).Value = BP_Code

        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function DeleteLoad_Unload_All(ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " DELETE FROM Load_Unload_Vessel WHERE Booking_no = @Booking_no; "
        sql &= " DELETE FROM Load_Unload_Product WHERE Booking_no = @Booking_no; "
        sql &= " DELETE FROM Load_Unload_Addition WHERE Booking_no = @Booking_no; "
        sql &= " DELETE FROM Load_Unload_Delay WHERE Booking_no = @Booking_no; "
        sql &= " DELETE FROM Load_Unload_Remark WHERE Booking_no = @Booking_no; "
        sql &= " DELETE FROM Load_Unload_Product_Bulk WHERE Booking_no = @Booking_no; "
        sql &= " DELETE FROM Load_Unload_Addition_Stock WHERE Booking_no = @Booking_no; "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Addition(ByVal Booking_no As String, ByVal Green As String, ByVal Red As String, ByVal Yellow As String, ByVal Orange As String, ByVal Water As String, ByVal Additive As String, ByVal Disposal As String, ByVal Bunker_FO As String, ByVal Bunker_DO As String, ByVal Marker As String, ByVal Excise As String, ByVal Nitrogen As String, ByVal Electric As String, ByVal Hopper As String, ByVal Hopper_From As String, ByVal Hopper_To As String, ByVal Hopper_DateFrom As String, ByVal Hopper_DateTo As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Addition(Booking_no,Green,Additive,Red,Yellow,Orange,Water,Disposal,Bunker_FO,Bunker_DO,Marker,Excise,Nitrogen,Electric,Hopper,Hopper_From,Hopper_To,Hopper_Date_From,Hopper_Date_To) "
        sql &= " VALUES(@Booking_no,@Green,@Additive,@Red,@Yellow,@Orange,@Water,@Disposal,@Bunker_FO,@Bunker_DO,@Marker,@Excise,@Nitrogen,@Electric,@Hopper,@Hopper_From,@Hopper_To,@Hopper_Date_From,@Hopper_Date_To)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Green", SqlDbType.NVarChar, 10).Value = Green
        cmd.Parameters.Add("@Additive", SqlDbType.NVarChar, 10).Value = Additive
        cmd.Parameters.Add("@Red", SqlDbType.NVarChar, 10).Value = Red
        cmd.Parameters.Add("@Yellow", SqlDbType.NVarChar, 10).Value = Yellow
        cmd.Parameters.Add("@Orange", SqlDbType.NVarChar, 10).Value = Orange
        If (Water = "") Then
            Water = "0"
        End If
        cmd.Parameters.Add("@Water", SqlDbType.NVarChar, 10).Value = Water
        cmd.Parameters.Add("@Disposal", SqlDbType.NVarChar, 10).Value = Disposal
        cmd.Parameters.Add("@Bunker_FO", SqlDbType.NVarChar, 10).Value = Bunker_FO
        cmd.Parameters.Add("@Bunker_DO", SqlDbType.NVarChar, 10).Value = Bunker_DO
        cmd.Parameters.Add("@Marker", SqlDbType.NVarChar, 10).Value = Marker
        cmd.Parameters.Add("@Excise", SqlDbType.NVarChar, 10).Value = Excise
        cmd.Parameters.Add("@Nitrogen", SqlDbType.NVarChar, 10).Value = Nitrogen
        cmd.Parameters.Add("@Electric", SqlDbType.NVarChar, 10).Value = Electric
        cmd.Parameters.Add("@Hopper", SqlDbType.NVarChar, 10).Value = Hopper
        cmd.Parameters.Add("@Hopper_From", SqlDbType.NVarChar, 5).Value = Hopper_From
        cmd.Parameters.Add("@Hopper_To", SqlDbType.NVarChar, 5).Value = Hopper_To
        cmd.Parameters.Add("@Hopper_Date_From", SqlDbType.NVarChar, 12).Value = Hopper_DateFrom
        cmd.Parameters.Add("@Hopper_Date_To", SqlDbType.NVarChar, 12).Value = Hopper_DateTo
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function InsertLoad_Unload_Addition_Stock(ByVal Booking_no As String, ByVal Stock_Code As String, ByVal Grade As String, ByVal Brand As String, ByVal Count As String, ByVal Status As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Load_Unload_Addition_Stock(Booking_no,Stock_Code,Grade,Brand,Count,Status) "
        sql &= " VALUES(@Booking_no,@Stock_Code,@Grade,@Brand,@Count,@Status)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Stock_Code", SqlDbType.NVarChar, 16).Value = Stock_Code
        cmd.Parameters.Add("@Grade", SqlDbType.NVarChar, 50).Value = Grade
        cmd.Parameters.Add("@Brand", SqlDbType.NVarChar, 15).Value = Brand
        cmd.Parameters.Add("@Count", SqlDbType.NVarChar, 25).Value = Count
        cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 1).Value = Status
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function sendmail(ByVal Tos As [String], ByVal CCs As [String], ByVal Subjects As [String], ByVal Bodys As [String], ByVal pathfilenameAttachServer As [String]) As [String]
        'Dim x As [String] = ""
        'Try
        '    Dim client As SmtpClient = New SmtpClient("owa.irpc.in.th")
        '    ' client.DeliveryMethod = SmtpDeliveryMethod.Network

        '    ' client.UseDefaultCredentials = False
        '    ' client.EnableSsl = False
        '    client.Credentials = New System.Net.NetworkCredential("IRPC\port.customerservice", "Init1234")
        '    Dim message As MailMessage = New MailMessage("port.customerservice@irpc.co.th", "port.customerservice@irpc.co.th")
        '    message.Subject = Subjects

        '    message.Body = "XX"

        '    client.Send(message)
        'Catch ex As Exception
        '    x = ex.Message
        'End Try
        'Return x



        Dim objmail As New MailMessage()
        Dim MAILFROM As String = ConfigurationManager.AppSettings("MAILFROM").ToString()
        Dim MAILFORNAME As String = ConfigurationManager.AppSettings("MAILFORMNAME").ToString()
        Dim USERSMTP As String = ConfigurationManager.AppSettings("USERSMTP").ToString()
        Dim PASSSMTP As String = ConfigurationManager.AppSettings("PASSSMTP").ToString()
        Dim SMTPSSL As String = ConfigurationManager.AppSettings("SMTPSSL").ToString()
        Dim SMTP As String = ConfigurationManager.AppSettings("SMTP").ToString()
        Dim SMTPPORT As String = ConfigurationManager.AppSettings("SMTPPORT").ToString()
        Dim SUBJECT As String = ConfigurationManager.AppSettings("SUBJECT").ToString()
        Dim Smtpclient1 As New SmtpClient(SMTP)

        Dim s As New MailAddress(MAILFROM, MAILFORNAME)
        Dim x As [String] = ""
        Try
            objmail.From = s
            If Tos <> "" Then
                Dim arr As [String]() = Tos.Split(";")
                For i As Integer = 0 To arr.Length - 1
                    If arr(i).ToString() <> "" Then
                        objmail.[To].Add(arr(i).ToString())
                    End If
                Next
            End If

            If CCs <> "" Then
                objmail.CC.Add(CCs)
            End If
            objmail.Subject = SUBJECT
            objmail.Body = Bodys
            objmail.IsBodyHtml = True
            objmail.Priority = MailPriority.Normal

            If USERSMTP <> "" Then
                Smtpclient1.Credentials = New System.Net.NetworkCredential(USERSMTP, PASSSMTP)
            End If

            If SMTPSSL = "TRUE" Then
                Smtpclient1.EnableSsl = True
            Else
                Smtpclient1.EnableSsl = False
            End If

            If pathfilenameAttachServer <> "" Then
                objmail.Attachments.Add(New Attachment(pathfilenameAttachServer))
            End If
            ' Smtpclient1.Host = SMTP
            'Smtpclient1.Port = Convert.ToInt32(SMTPPORT)
            Smtpclient1.Send(objmail)
        Catch ex As Exception
            x = ex.Message
        End Try
        Return x
    End Function

    Public Function runupdateBulk(ByVal Booking_no As String, ByVal Product_no As String, ByVal BP_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Load_Unload_Product_Bulk SET "
        sql &= " BP_Code = @BP_Code "
        sql &= " Where Booking_no = @Booking_no"
        sql &= " and Product_no = @Product_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@BP_Code", SqlDbType.NVarChar, 25).Value = BP_Code
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function runupdate(ByVal Booking_no As String, ByVal Product_no As String, ByVal BP_Code As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " UPDATE Load_Unload_Product SET "
        sql &= " BP_Code = @BP_Code "
        sql &= " Where Booking_no = @Booking_no"
        sql &= " and Product_no = @Product_no "

        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        cmd.Parameters.Add("@Product_no", SqlDbType.NVarChar, 10).Value = Product_no
        cmd.Parameters.Add("@BP_Code", SqlDbType.NVarChar, 25).Value = BP_Code
        ret = cmd.ExecuteNonQuery()

        cmd.Dispose()
        Return ret
    End Function

    Public Function Insert_Error_Logs(ByVal UserName As String, ByVal ErrorDate As Date, ByVal ErrorOnPage As String, ByVal ErrorOnFunction As String, ByVal ErrorMsg As String, ByVal Booking_no As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        sql = " INSERT Error_Logs(UserLogon, ErrorDate, ErrorOnPage, ErrorOnFunction, ErrorMessage, Booking_no) "
        sql &= " VALUES(@UserLogon, @ErrorDate, @ErrorOnPage, @ErrorOnFunction, @ErrorMessage, @Booking_no)"
        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If
        cmd.Parameters.Clear()
        cmd.Parameters.Add("@UserLogon", SqlDbType.NVarChar, 10).Value = UserName
        cmd.Parameters.Add("@ErrorDate", SqlDbType.DateTime).Value = ErrorDate
        cmd.Parameters.Add("@ErrorOnPage", SqlDbType.NVarChar, 200).Value = ErrorOnPage
        cmd.Parameters.Add("@ErrorOnFunction", SqlDbType.NVarChar, 100).Value = ErrorOnFunction
        cmd.Parameters.Add("@ErrorMessage", SqlDbType.Text).Value = ErrorMsg
        cmd.Parameters.Add("@Booking_no", SqlDbType.NVarChar, 10).Value = Booking_no
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

	    Public Function InsertTableConfigure(ByVal e As String, ByVal UserName As String, ByVal PageName As String, ByVal TableName As String, ByVal Header_ID As String, ByVal Header_Index As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim adap As New SqlDataAdapter()
        Dim sql As String = ""
        Dim ret As Integer = 0
        If e = "UPDATE" Then
            sql = "UPDATE TableColumn_Configure SET " & vbCrLf
            sql &= "UserName = @UserName," & vbCrLf
            sql &= "PageName = @PageName," & vbCrLf
            sql &= "TableName = @TableName," & vbCrLf
            sql &= "Header_ID = @Header_ID," & vbCrLf
            sql &= "Header_Index = @Header_Index" & vbCrLf
            'sql &= "Header_Status = @Header_Status" & vbCrLf
            sql &= "WHERE UserName = @UserName" & vbCrLf
            sql &= "AND PageName = @PageName" & vbCrLf
            sql &= "AND TableName = @TableName" & vbCrLf
            sql &= "AND Header_ID = @Header_ID"
        Else
            sql = "INSERT TableColumn_Configure(UserName, PageName, TableName, Header_ID, Header_Index)" & vbCrLf
            sql &= "VALUES(@UserName, @PageName, @TableName, @Header_ID, @Header_Index)"
        End If



        Dim cmd As New SqlCommand(sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@UserName", SqlDbType.NVarChar, 50).Value = UserName.ToString()
        cmd.Parameters.Add("@PageName", SqlDbType.NVarChar, 50).Value = PageName.ToString()
        cmd.Parameters.Add("@TableName", SqlDbType.NVarChar, 50).Value = TableName.ToString()
        cmd.Parameters.Add("@Header_ID", SqlDbType.NVarChar, 50).Value = Header_ID.ToString()
        cmd.Parameters.Add("@Header_Index", SqlDbType.NVarChar, 50).Value = Header_Index
        'cmd.Parameters.Add("@Header_Status", SqlDbType.NVarChar, 50).Value = Header_Status.ToString)
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function

    Public Function UpdateClearAdvancePayment(ByVal Booking As String, ByVal PaymentRemark As String, ByRef conn As SqlConnection, ByRef tran As SqlTransaction) As Integer
        Dim ret As Integer = 0
        Dim Sql As String = ""
        Sql += "UPDATE Booking SET Payin = 1, "
        Sql += "PaymentRemark = @PaymentRemark "
        Sql += "WHERE Booking_no = @Booking"

        Dim cmd As New SqlCommand(Sql, conn)
        If Not (tran Is Nothing) Then
            cmd.Connection = conn
            cmd.Transaction = tran
        End If

        cmd.Parameters.Clear()
        cmd.Parameters.Add("@Booking", SqlDbType.NVarChar, 15).Value = Booking.ToString()
        cmd.Parameters.Add("@PaymentRemark", SqlDbType.NVarChar, 200).Value = PaymentRemark.ToString()
        ret = cmd.ExecuteNonQuery()
        cmd.Dispose()
        Return ret
    End Function
	
End Class
